From: 7stud -- Date: 2009-07-23T20:32:58+09:00 Subject: Re: Ruby "star".... what's it? Max Williams wrote: > > 7stud - am i right in thinking that if i do this > > a, b = 1, 2 > > ruby is automatically starring just the right side of the expression, > under the hood? eg > In pickaxe2, p. 91, the rule is: ---- When an assignment has more than one lvalue, the assignment expression returns an array of the rvalues. Testing that out: ---- result = (x, y = [1], [2, 3]) p result So I guess you could say "ruby is automatically starring the right hand side of a parallel assignment if there is more than one lvalue, and the resulting array is the value of the entire expression. And I guess this wasn't a very good example: x, y, z = *[1, 2, 3] puts x, y, z --output:-- 1 2 3 Because you can eliminate the star and get the same output: x, y, z = [1, 2, 3] p x p y p z --output:-- 1 2 3 But this is where the star makes a difference: x, y, z = 1, [2, 3] p x p y p z --output:-- 1 [2, 3] nil x, y, z = 1, *[2, 3] p x p y p z --output:-- 1 2 3 (This applies to ruby 1.8. See David Black's post for 1.9 behavior.) -- Posted via http://www.ruby-forum.com/.