From: "Jesús Gabriel y Galán" Date: 2008-11-19T20:37:21+09:00 Subject: Re: Run a method in a Module On Wed, Nov 19, 2008 at 12:19 PM, Mario Ruiz wrote: > In my case is a little bit more complicated since the modules I'll use > are the output of another application and I cannot change the content. > I'm doing something like: > > m1=Module1 > m1.instance_methods.each {|b| > # here I'm checking if the methods exist on Module2 > # Also I'm running the method and getting the result in both modules > } One way I managed to do it, although I'm not sure it makes sense for your case is: irb(main):039:0> module Test irb(main):040:1> def met irb(main):041:2> puts "hi" irb(main):042:2> end irb(main):043:1> end => nil irb(main):053:0> o = Object.new irb(main):054:0> o.extend(Test) => # irb(main):057:0> Test.instance_method("met").bind(o).call hi That's because to call an instance method you need an object that is the instance. So we build a "fake" object, extend it with the module, bind the method to it and call it. Or you could just call the method directly on the object: irb(main):059:0> o.send("met") hi So for your case: irb(main):060:0> o = Object.new => # irb(main):061:0> o.extend(Test) => # irb(main):062:0> Test.instance_methods.each {|m| o.send(m)} hi Of course this assumes (and I think that your use case too) that the instance methods of the Module don't expect anything in the instance binding they are called: i.e. they don't expect an 'each' method defined or something like that. Jesus.