# Question about .send()

**URL:** <https://www.ruby-forum.com/t/question-about-send/150587>\
**Category:** Rails\
**Created:** [October 10, 2008, 7:44am UTC](https://www.ruby-forum.com/t/question-about-send/150587 "2008-10-10T07:44:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Garrett\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4da419/32.png) [@Garrett\_B](https://www.ruby-forum.com/u/Garrett_B)\
**Post date:** [October 10, 2008, 7:44am UTC](https://www.ruby-forum.com/t/question-about-send/150587/1 "2008-10-10T07:44:22Z")

</div>

I love that I can use .send() to dynamically build the name of the  
method I want to call, but how do I build a variable length list of  
parameters to go along with it?

I am trying to write a helper for dealing with routing and nested  
resources. Rails sets me up with methods the look like this;

edit\_resource\_path (resource)  
edit\_resource\_nested\_path(resource, nested)  
edit\_resource\_nested\_double\_nested\_path(resource, nested,  
double\_nested)

…and so on as deep as I have nested my resources.

I can easily construct the name of the method I have to call like  
this;  
method\_name = (“edit\_#{object.class.to\_s.underscore}\_path”)

…but to call it with .send() I need to supply various sets of  
parameters. I was hoping I could just stuff them in an array and send  
the array, but this didn’t work. any other ideas?

---

<div class="post-metadata">

**Author:** ![Garrett\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4da419/32.png) [@Garrett\_B](https://www.ruby-forum.com/u/Garrett_B)\
**Post date:** [October 10, 2008, 8:51am UTC](https://www.ruby-forum.com/t/question-about-send/150587/2 "2008-10-10T08:51:08Z")

</div>

On Oct 10, 6:43 am, Garrett B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> …but to call it with .send() I need to supply various sets of  
> parameters. I was hoping I could just stuff them in an array and send  
> the array, but this didn’t work. any other ideas?

foo.send(:some\_method, \*array\_of\_parameters)

Fred

---

<div class="post-metadata">

**Author:** ![Garrett\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4da419/32.png) [@Garrett\_B](https://www.ruby-forum.com/u/Garrett_B)\
**Post date:** [October 10, 2008, 8:55am UTC](https://www.ruby-forum.com/t/question-about-send/150587/3 "2008-10-10T08:55:49Z")

</div>

On Oct 10, 1:43 pm, Garrett B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> double\_nested)
> 
> …and so on as deep as I have nested my resources.
> 
> I can easily construct the name of the method I have to call like  
> this;  
> method\_name = (“edit\_#{object.class.to\_s.underscore}\_path”)
> 
> …but to call it with .send() I need to supply various sets of  
> parameters. I was hoping I could just stuff them in an array and send  
> the array, but this didn’t work. any other ideas?

arg = [param1, param2, …]  
Object.send(method, \*arg)
