From: "David A. Black" Date: 2005-05-21T00:58:00+09:00 Subject: Re: Multiple return and parallel assignement Hi -- On Sat, 21 May 2005, Eric Mahurin wrote: > yep. return 1,2 and return [1,2] work the same. Also when the > RHS or LHS of an assign is only single item and the other side > is multiple items you can think of that single item being > splatted (*): > > a = 1,2 # *a = 1,2 # a = [1,2] > a,b = [1,2] # a,b = *[1,2] # a,b = 1,2 Although: *a = *[1,2] # a == [1,2] :-) It's hard, I find, to come up with an exact description of what the unarr?ay (unary unarray) operator does that fits every case. The closest I've come is: *a = x means: a gets assigned that which, when stripped of one level of array-ness, is x. Thus: *a = 1,2 # [1,2] stripped of [] is 1,2 so a is [1,2] *a = *[1,2] # a stripped of [] is [1,2] stripped of [], so # a is [1,2] def x(*args); end x(1,2,3) # [1,2,3] stripped of [] is 1,2,3, so args is [1,2,3] x([1,2,3]) # [[1,2,3]] stripped of [] is [1,2,3], so args # is [[1,2,3]] Then there's a = 1,2 # automatic arraying -- the opposite of * a = *[1,2] # un-arraying followed by automatic arraying :-) or something like that. David -- David A. Black dblack@wobblini.net