Ruby - Variable Argument Length

Introduction

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:

Demo

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

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

Result