From: "Mauricio Fernández" Date: 2004-08-28T04:50:24+09:00 Subject: Re: Method name to method object On Sat, Aug 28, 2004 at 04:42:40AM +0900, Sean O'Dell wrote: > I want to obtain method objects given their string names. I can't figure out > how to get the method object for MyMethod::mymeth given the string name > "MyMethod::mymeth". I don't know the name of the module in advance, or even > if any was given (or even how many levels of modules deep the method is), so > I can't use something like MyMethod::method("mymeth"). > > How does one do that? >> module A; module B; def self.foo; "foo" end end end => nil >> def get_smethod(str); a=str.split(/::/); m=a.pop; a.inject(Object){|s,x|s.const_get(x)}.method(m) end => nil >> get_smethod("A::B::foo").call => "foo" You might want to use '.foo' and split on /\./ to get the method... -- Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com