class Speaker

def say_hello

" hello "

end

end



module EnglishSpeaker

expects_method = Speaker . instance_method ( : say_hello )

define_method : say_hello do | * args |

expects_method . bind ( self ) . call ( * args )

end

end



class Speaker

undef say_hello

end



Speaker . new . say_hello Speaker . new . extend ( EnglishSpeaker ) . say_hello

I was recently working with a framework that reopened and defined a method on Object. I wanted the behavior of the framework, but I also wanted to define my own behavior. This is generally the case for alias_method_chain or one of the other Alternatives for Redefining Methods , but my circumstances (to be discussed in a subsequent post) prevented me from using one of the better known solutions.The solution that worked for me was to move the original method definition to a module.You may never need this technique, I only needed it once in the past 2.5 years. But, when it applied I found it to be significantly better than the alternatives.