using a local variable for method calls

Discussion in 'Ruby' started by Reid Oda, Apr 2, 2008.

  1. Reid Oda

    Reid Oda Guest

    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-forum.com/.
     
    Reid Oda, Apr 2, 2008
    #1
    1. Advertising

  2. Reid Oda

    Tim Hunter Guest

    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.rubyforge.org/
    RMagick 2: http://rmagick.rubyforge.org/rmagick2.html
     
    Tim Hunter, Apr 2, 2008
    #2
    1. Advertising

  3. Reid Oda

    Reid Oda Guest

    awesome!

    Tim Hunter wrote:
    > Reid Oda wrote:
    >> end
    >>
    >> -reid

    >
    > Check out the _send_ method.
    >
    > update._send_(key, *args)


    --
    Posted via http://www.ruby-forum.com/.
     
    Reid Oda, Apr 2, 2008
    #3
  4. Reid Oda

    Robert Dober Guest

    On Thu, Apr 3, 2008 at 12:13 AM, Tim Hunter <> 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.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
     
    Robert Dober, Apr 3, 2008
    #4
  5. Reid Oda

    Marc Heiler Guest

    Marc Heiler, Apr 3, 2008
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Patrick Hoffmann
    Replies:
    3
    Views:
    2,850
    Christian Jan├čen
    Aug 8, 2003
  2. Honne Gowda A
    Replies:
    2
    Views:
    891
    Karl Heinz Buchegger
    Oct 31, 2003
  3. andy6
    Replies:
    2
    Views:
    772
    andy6 via DotNetMonster.com
    Jun 9, 2006
  4. Richard Tobin
    Replies:
    24
    Views:
    812
  5. John Davison
    Replies:
    1
    Views:
    102
    Richard Cornford
    Mar 6, 2007
Loading...

Share This Page