views:

1763

answers:

3

Hi All,

I have a method in a rails helper file like this

def table_for(collection, *args)
 options = args.extract_options!
 ...
end

and i want to be able to call this method like this

args = [:name, :description, :start_date, :end_date]
table_for(@things, args)

so that I can dynamically pass in the arguments based on a form commit. I can't rewrite the method, because I use it in too many places, how else can I do this?

Thanks,

-C

+3  A: 

just call it this way:

                       table_for(@things, *args)

the splat '*' operator will do the job, without having to modify the method.

Maximiliano Guzman
+6  A: 
sean lynch
A: 

You should be able to call it with the splat too and it'll be expanded to all those args. So:

table_for(@things, *args)