Method: Module#redefine_method
- Defined in:
- lib/olelo/extensions.rb
#redefine_method(name) { ... } ⇒ void
This method returns an undefined value.
Redefine a module method
Replaces alias_method_chain and allows to call overwritten method via super.
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/olelo/extensions.rb', line 41 def redefine_method(name, &block) if instance_methods(false).any? {|x| x.to_s == name.to_s } method = instance_method(name) mod = Module.new do define_method(name) {|*args| method.bind(self).call(*args) } end remove_method(name) include(mod) end include(Module.new { define_method(name, &block) }) end |