using a local variable for method calls

R

Reid Oda

hello all,

first off, thanks for all the help this board/list has offered. it has
been fantastic.

a workmate of mine and i are puzzling over this problem. here is a bit
of pseudo code that represents it:

somehash.each_key do |key|
update.key "something"
end

obviously there is a problem with using the "key" variable to make the
method call. how can we accomplish this elegantly? we've considered
this:

somehash.each_key do |key|
eval("update.#{key}(\"something\")")
end

but that seems a bit cludgey. does anyone have some advice?

-reid
 
T

Tim Hunter

Reid said:
hello all,

first off, thanks for all the help this board/list has offered. it has
been fantastic.

a workmate of mine and i are puzzling over this problem. here is a bit
of pseudo code that represents it:

somehash.each_key do |key|
update.key "something"
end

obviously there is a problem with using the "key" variable to make the
method call. how can we accomplish this elegantly? we've considered
this:

somehash.each_key do |key|
eval("update.#{key}(\"something\")")
end

but that seems a bit cludgey. does anyone have some advice?

-reid

Check out the _send_ method.

update._send_(key, *args)
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top