Using a local variable for method calls

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

Reid O. wrote:

end

-reid

Check out the send method.

update.send(key, *args)

awesome!

Tim H. wrote:

Reid O. wrote:

end

-reid

Check out the send method.

update.send(key, *args)

Maybe he tried to introduce a new way … :wink:

On Thu, Apr 3, 2008 at 12:13 AM, Tim H. [email protected] wrote:

end

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

-reid

Check out the send method.

update.send(key, *args)
you surely mean
update.send(…) or
update.send(…)
right?

Cheers
Robert


RMagick: http://rmagick.rubyforge.org/
RMagick 2: http://rmagick.rubyforge.org/rmagick2.html


http://ruby-smalltalk.blogspot.com/


Whereof one cannot speak, thereof one must be silent.
Ludwig Wittgenstein

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs