From: "Iñaki Baz Castillo" Date: 2010-01-08T18:49:42+09:00 Subject: Re: when to use * arguments? El Viernes, 8 de Enero de 2010, Zhenning Guan escribió: > version one: > > def say(*a) > a.each {|r| puts r } > end > > say(1,2,3) > ------ > > version two: > > def say(a) > a.each {|r| puts r } > end > > say([1,2,3]) > ------- > So, any different here? when should we * arguments like version one? * is useful when you don't know the number and kind of arguments the method will receive. Using * will convert any arguments to an Array. In your first version: irb> say 123 123 [123] <-- returns an Array In your second version: irb> say 123 NoMethodError: undefined method `each' for 2:Fixnum from (irb):6:in `say' -- Iñaki Baz Castillo