Issue #4254 has been updated by duerst (Martin Dürst).


matz (Yukihiro Matsumoto) wrote:
> I'd like to allow method transplanting from a module, not a class, to either class or module.
> Any objection?

I think this is a step in the right direction. Both JavaScript and Python allow functions (including what are essentially methods) to be assigned arbitrarily. There are often better ways to achieve the same thing in Ruby, but sometimes, there's not much of an alternative.

[Some of my students were working on a project to automatically convert Python programs to Ruby, and this is a very hard wall we bumped into.]
----------------------------------------
Feature #4254: Allow method transplanting
https://bugs.ruby-lang.org/issues/4254#change-27402

Author: zimbatm (Jonas Pfenniger)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: 2.0.0


=begin
Is there a technical reason to not allow re-binding a method from one module to any other module ?
 
  module M
    def foo; "foo"; end
  end

  module N; end
  N.send(:define_method, :foo, M.instance_method(:foo)) #=> should not raise
 
It's like monkey-patching. Powerful, dangerous, but also really useful. It could allow different variations of method_wrap or alias_method_chain that are not possible right now.
=end



-- 
http://bugs.ruby-lang.org/