From: Max Williams Date: 2009-07-23T18:50:29+09:00 Subject: Re: Ruby "star".... what's it? Mirko Viviani wrote: > Sorry, > Complete code was like this > x, *xs = *myarray > > after executing, x is 1 and xs [2,3,4,5,6,6] ..... :o > > 2009/7/23 Max Williams Ah, well there you go. In ruby, you can assign multiple variables to multiple values simultaneously: effectively on the left side of the = you have a list of variables and on the right you have a list of values. If the sizes of the lists don't match up then any extra values are thrown away and any extra variables are set to nil. eg However, if you use the * on the rightmost variable, then any extra values get pulled into an array and that variable points to that array: >> a, b, c = 1, 2, 3 => [1, 2, 3] >> puts a.inspect; puts b.inspect; puts c.inspect 1 2 3 => nil >> a, b, c = 1, 2 => [1, 2] >> puts a.inspect; puts b.inspect; puts c.inspect 1 2 nil => nil >> a, b = 1, 2, 3 => [1, 2, 3] >> puts a.inspect; puts b.inspect 1 2 => nil >> a, *b = 1, 2, 3 => [1, 2, 3] >> puts a.inspect; puts b.inspect 1 [2, 3] -- Posted via http://www.ruby-forum.com/.