Feature #4254: Allow method transplanting
http://redmine.ruby-lang.org/issues/show/4254

Author: Jonas Pfenniger
Status: Open, Priority: Normal
Category: core, Target version: 1.9.3

Is there a technical reason to not allow re-binding a method from one mod=
ule to any other module ?

  module M
    def foo; "foo"; end
  end

  module N; end
  N.send(:define_method, :foo, M.instance_method(:foo)) #=3D> should not =
raise

It's like monkey-patching. Powerful, dangerous, but also really useful. I=
t could allow different variations of method_wrap or alias_method_chain t=
hat are not possible right now.


----------------------------------------
http://redmine.ruby-lang.org
RnJvbSAwMzM2ZWMzMzRmN2ViNjZkMmNmMDViZDdhMjlkNzQ4NzgwZDYwNDRl
IE1vbiBTZXAgMTcgMDA6MDA6MDAgMjAwMQpGcm9tOiBKb25hcyBQZmVubmln
ZXIgPGpvbmFzQHBmZW5uaWdlci5uYW1lPgpEYXRlOiBTdW4sIDkgSmFuIDIw
MTEgMDA6MTM6NTcgKzAwMDAKU3ViamVjdDogW1BBVENIXSBtZXRob2QgdHJh
bnNwbGFudGluZzogQWxsb3cgdG8gc2V0IGFuIFVuYm91bmRNZXRob2QgdG8g
YW55IG1vZHVsZS4KCkl0J3MgdGltZSB0byBncm93IHVwLCByZW1vdmUgdGhl
IHNlY3VyaXR5IG5ldHMuCi0tLQogcHJvYy5jIHwgICAxMSAtLS0tLS0tLS0t
LQogMSBmaWxlcyBjaGFuZ2VkLCAwIGluc2VydGlvbnMoKyksIDExIGRlbGV0
aW9ucygtKQoKZGlmZiAtLWdpdCBhL3Byb2MuYyBiL3Byb2MuYwppbmRleCA3
ZGYyZWM4Li42NTJiM2UxIDEwMDY0NAotLS0gYS9wcm9jLmMKKysrIGIvcHJv
Yy5jCkBAIC0xMjkzLDE3ICsxMjkzLDYgQEAgcmJfbW9kX2RlZmluZV9tZXRo
b2QoaW50IGFyZ2MsIFZBTFVFICphcmd2LCBWQUxVRSBtb2QpCiAgICAgaWYg
KHJiX29ial9pc19tZXRob2QoYm9keSkpIHsKIAlzdHJ1Y3QgTUVUSE9EICpt
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