# Using a local variable for method calls

**URL:** <https://www.ruby-forum.com/t/using-a-local-variable-for-method-calls/133725>\
**Category:** Ruby\
**Created:** [April 3, 2008, 12:10am UTC](https://www.ruby-forum.com/t/using-a-local-variable-for-method-calls/133725 "2008-04-03T00:10:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![brownerthanu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e5b9ba/32.png) [@brownerthanu](https://www.ruby-forum.com/u/brownerthanu)\
**Post date:** [April 3, 2008, 12:10am UTC](https://www.ruby-forum.com/t/using-a-local-variable-for-method-calls/133725/1 "2008-04-03T00:10:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![brownerthanu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e5b9ba/32.png) [@brownerthanu](https://www.ruby-forum.com/u/brownerthanu)\
**Post date:** [April 3, 2008, 12:14am UTC](https://www.ruby-forum.com/t/using-a-local-variable-for-method-calls/133725/2 "2008-04-03T00:14:47Z")

</div>

Reid O. wrote:

> end
> 
> -reid

Check out the _send_ method.

update._send_(key, \*args)

---

<div class="post-metadata">

**Author:** ![brownerthanu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e5b9ba/32.png) [@brownerthanu](https://www.ruby-forum.com/u/brownerthanu)\
**Post date:** [April 3, 2008, 12:26am UTC](https://www.ruby-forum.com/t/using-a-local-variable-for-method-calls/133725/3 "2008-04-03T00:26:02Z")

</div>

awesome!

Tim H. wrote:

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

---

<div class="post-metadata">

**Author:** ![brownerthanu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e5b9ba/32.png) [@brownerthanu](https://www.ruby-forum.com/u/brownerthanu)\
**Post date:** [April 3, 2008, 1:39pm UTC](https://www.ruby-forum.com/t/using-a-local-variable-for-method-calls/133725/4 "2008-04-03T13:39:55Z")

</div>

Maybe he tried to introduce a new way … 😉

---

<div class="post-metadata">

**Author:** ![brownerthanu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e5b9ba/32.png) [@brownerthanu](https://www.ruby-forum.com/u/brownerthanu)\
**Post date:** [April 3, 2008, 11:22am UTC](https://www.ruby-forum.com/t/using-a-local-variable-for-method-calls/133725/5 "2008-04-03T11:22:42Z")

</div>

On Thu, Apr 3, 2008 at 12:13 AM, Tim H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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/](http://rmagick.rubyforge.org/)  
> RMagick 2: [http://rmagick.rubyforge.org/rmagick2.html](http://rmagick.rubyforge.org/rmagick2.html)

–  
[http://ruby-smalltalk.blogspot.com/](http://ruby-smalltalk.blogspot.com/)

* * *

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