[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Calling a method whose name I only know at run-time

Builder Chad

2/3/2007 10:53:00 AM

Hi folks,

I have a handful of methods that perform operations on chunks of data.
Which of these methods is called is specified in a YAML configuration so
I only know the method names at run-time, which are, of course, strings.
I am familiar with eval but would like to avoid using it to keep my code
safe. Is there another way I can do it?

Thanks,

Chad.

--
Posted via http://www.ruby-....

4 Answers

Builder Chad

2/3/2007 11:04:00 AM

0

Oops, solved it. Sorry, I missed Object#method the first time around.
8)

--
Posted via http://www.ruby-....

Jano Svitok

2/3/2007 11:23:00 AM

0

On 2/3/07, Chad Thatcher <chad@zulu.net> wrote:
> Oops, solved it. Sorry, I missed Object#method the first time around.
> 8)

And there is the Object#send that will do what you want, i.e.
any_object.send("method1", arg1, arg2)

or

any_object.send("method1", *args)

(if send insists on symbols for method names, use String#to_sym)

dblack

2/3/2007 1:13:00 PM

0

Builder Chad

2/3/2007 6:23:00 PM

0

It looks like send is actually more appropriate for my needs, thanks,
I'll give it a go.

--
Posted via http://www.ruby-....