Ruby - Variable Argument Length


A method may need to be capable of receiving an uncertain number of arguments.

Ruby can accept any number of trailing items by preceding the final argument with an asterisk:


def aMethod( a=10, b=20, c=100, *d )
   return a, b, c, d
end# from   w  w w.j a  v  a 2  s.  c om

p( aMethod( 1,2,3,4,6 ) )     #=> displays: [1, 2, 3, [4, 6]]