I have a method that receives about 20 arguments, in that argument I would like to pass all those to another method. Can I pass them all into the second method without retyping them all? Is there an args array or something that I can pass?
What I have:
def my_method(arg1, arg2, ..., arg20)
#do some stuff
my_second_method(arg1, arg2, ..., arg20)
#do other stuff
end
What I would like:
def my_method(arg1, arg2, ..., arg20)
#do some stuff
my_second_method(args[array])
#do other stuff
end
Having a method that accepts that many arguments is a code smell. This method is almost surely trying to do too many things with too many different kinds of data.
That said, if this is unavoidable, try this approach, using Ruby’s splat operator.