# A proper Ruby way to call a procedure by name

**URL:** <https://www.ruby-forum.com/t/a-proper-ruby-way-to-call-a-procedure-by-name/155605>\
**Category:** Ruby\
**Created:** [December 14, 2008, 3:06pm UTC](https://www.ruby-forum.com/t/a-proper-ruby-way-to-call-a-procedure-by-name/155605 "2008-12-14T15:06:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [December 14, 2008, 3:06pm UTC](https://www.ruby-forum.com/t/a-proper-ruby-way-to-call-a-procedure-by-name/155605/1 "2008-12-14T15:06:12Z")

</div>

I know how to do this using a case statement but I want to know if  
there’s a more Rubyesque way of doing things.

I’m screen scraping from a lot of different sources. They all have much  
same data but it’s presented in different ways with different access  
methods. I use scRubyt to do the scraping and define most of the setup  
for each way of presenting things in hashes which are read in from yaml  
files. That way I can nearly DRY everything up into a few simple Ruby  
routines with all the differences between the websites extracted into  
data files.

But there’s one area I’m not satisfied with because some cases are so  
different from the others that I have to write special routines just  
for them. That’s ok and I can name the routines to be used for those  
cases in the yaml file. Then when the yaml config file is read in I can  
use a switch statement to tell me how to process the data from each site  
along the lines of

result = case value  
when name1\_from\_yaml: result1(param1,param2)  
when name2\_from\_yaml: result2(param1,param2)  
etc  
end

which is fine and dandy but what I really want to do is to be able to  
put the name of the function to call into the yaml data file and then  
somehow get to

result = function\_named\_in\_yaml\_file(param1,param2)

How do I do this in Ruby? In other words I want a string or symbol to  
invoke a procedure without going via a case statement.

Ta

John S.

---

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [December 14, 2008, 3:53pm UTC](https://www.ruby-forum.com/t/a-proper-ruby-way-to-call-a-procedure-by-name/155605/2 "2008-12-14T15:53:14Z")

</div>

John S. wrote:

> etc
> 
> Ta
> 
> John S.

ri Object# **send**

obj. **send** (method\_name, arg1, arg2…)

---

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [December 15, 2008, 1:37pm UTC](https://www.ruby-forum.com/t/a-proper-ruby-way-to-call-a-procedure-by-name/155605/3 "2008-12-15T13:37:30Z")

</div>

Tim

OK, thanks for that. I knew it had to be simple

> > John S.
> 
> ri Object# **send**
> 
> obj. **send** (method\_name, arg1, arg2…)
