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  www .j a  v  a  2  s  .c  o m

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