Method name to method object

S

Sean O'Dell

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?

Sean O'Dell
 
M

Mauricio Fernández

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?
=> "foo"

You might want to use '.foo' and split on /\./ to get the method...
 
S

Sean O'Dell

=> nil


=> nil


=> "foo"

You might want to use '.foo' and split on /\./ to get the method...

Works very well, thank you. I didn't realize that module/class nestings were
accessible as constants.

Sean O'Dell
 
R

Robert Klemme

Sean O'Dell said:
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?

Sean O'Dell
=> #<Method: Foo#bar>

Kind regards

robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top