Question about .send()


#1

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?


#2

On Oct 10, 6:43 am, Garrett B. 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


#3

On Oct 10, 1:43 pm, Garrett B. 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)