Hi --

On Thu, 23 Jul 2009, Mirko Viviani wrote:

> Hi everybody.
> What means this snippet of code? Why use the "star" ?
>
> myarray = [1,2,3,4,5,6,6]
> qa = *myarray

In addition to the examples in the other answers, note that the star
has some new behavior in 1.9.

Here's the 1.8 behavior.

>> *a = 1; a
=> [1]
>> *a = [1]; a
=> [[1]]
>> *a = [[1]]; a
=> [[[1]]]


In each case, the star indicates one "missing" level of array
wrapping. In 1.9, that's changed:

>> *a = 1; a
=> [1]
>> *a = [1]; a
=> [1]
>> *a = [[1]]; a
=> [[1]]

*a = 1 and *a = [1] have the same result. (I know there was a lot of
discussion about this when it was being changed but I can't remember
exactly what the rationale was.)


David

-- 
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Now available: The Well-Grounded Rubyist (http://manning.com/black2)
Training! Intro to Ruby, with Black & Kastner, September 14-17
(More info: http://rubyurl.com/vmzN)