Jamey Cribbs
8/1/2006 11:12:00 PM
Harris Reynolds wrote:
> I am trying to call a method that has multiple arguments using reflection. However, when I invoke the method.call method passing the arguments as an array it chokes with the following error:
>
> ArgumentError (wrong number of arguments (1 for 4))
>
> The ruby interpreter thinks that my single array is the parameter I am passing in; however, the array I am passing in contains 4 object that map directly to the 4 arguments the interpreter is looking for. Is there another way to accomplish this other than using method.call? Or am I using method.call incorrectly?
>
> What is making this more difficult is the fact that the call I am making is completely dynamic so just calling:
>
> method_object.call arg1, arg2, arg3, arg4
>
> is not an option.
>
> thanks for any tips,
>
Try:
method_object.call(*args)
with args being the name of your argument array.
Jamey