From: Sean O'Halpin Date: 2009-02-22T03:42:23+09:00 Subject: Re: How to call a module method dynamically On Sat, Feb 21, 2009 at 4:58 PM, Adrian Klingel wrote: > I know about object instantiation and the send method, but the methods I > want to call are not in a class. They live in a module. > > module Foo > > module Bar > > def mymethod > "xyz" > end > > end > > end > > > I can call it statically, like: > > myvar = Foo::Bar::xyz > Can you? I get: irb --> myvar = Foo::Bar::xyz NoMethodError: undefined method `xyz' for Foo::Bar:Module Perhaps you meant: module Foo module Bar def self.mymethod "xyz" end end end myvar = Foo::Bar::mymethod # => "xyz" > But how can I call it dynamically. myvar = Foo::Bar.send("mymethod") # => "xyz" Regards, Sean