Hi --

On Sun, 15 Feb 2009, David Masover wrote:

> Jeff Moore wrote:
>>> Multiple assignment from array parameters is very useful as well...
>>> 
>>> ra_parm = [1,2,3]
>>> 
>>> def meth(ra_parm)
>>>  p1, p2, p3 = ra
>>> end
>>> 
>>> Regards
>>> 
>> 
>> Make that...
>>
>>  def meth(ra_parm)
>>    p1, p2, p3 = ra_parm
>>  end
>> 
>
> Don't you need a splat for that?
>
> def meth(ra_parm)
> p1, p2, p3 = *ra_parm
> end

No. If ra_parm is an array, it will assign in parallel to the
variables on the left.

irb(main):010:0> a,b,c = [1,2,3]
=> [1, 2, 3]
irb(main):011:0> a
=> 1
irb(main):012:0> b
=> 2
irb(main):013:0> c
=> 3


David

-- 
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2)

http://www.wishsight.com => Independent, social wishlist management!