[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

using a local variable for method calls

Reid Oda

4/2/2008 10:10:00 PM

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
--
Posted via http://www.ruby-....

4 Answers

Tim Hunter

4/2/2008 10:14:00 PM

0

Reid Oda wrote:
> 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)


--
RMagick: http://rmagick.ruby...
RMagick 2: http://rmagick.ruby...rmagick2.html

Reid Oda

4/2/2008 10:26:00 PM

0


awesome!

Tim Hunter wrote:
> Reid Oda wrote:
>> end
>>
>> -reid
>
> Check out the _send_ method.
>
> update._send_(key, *args)

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

Robert Dober

4/3/2008 9:22:00 AM

0

On Thu, Apr 3, 2008 at 12:13 AM, Tim Hunter <TimHunter@nc.rr.com> wrote:
>
> Reid Oda wrote:
>
> > 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)
you surely mean
update.send(...) or
update.__send__(...)
right?

Cheers
Robert
>
>
> --
> RMagick: http://rmagick.ruby...
> RMagick 2: http://rmagick.ruby...rmagick2.html
>
>



--
http://ruby-smalltalk.blo...

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

Marc Heiler

4/3/2008 11:40:00 AM

0

Maybe he tried to introduce a new way ... ;-)
--
Posted via http://www.ruby-....