From: "David A. Black" Date: 2004-12-01T03:32:25+09:00 Subject: Re: Unpacking an array with the star operator Hi -- On Wed, 1 Dec 2004, Robert Klemme wrote: > > "Brian Schr�der" schrieb im Newsbeitrag > news:20041130174018.40e55108@black.wg... > > Hello Group, > > > > I just noticed the following behaviour: > > > > $ irb --prompt-mode xmp > > *[:x] > > SyntaxError: compile error > > (irb):1: syntax error > > from (irb):1 > > a=*[:x] > > ==>:x > > > > and wondered why it is the case. I always understood the * operator as > pack/unpack array operator. So I would have expected the following > behaviour. > > > > *[:x] => :x > > No, it does not pack / unpack an array. You can only use it in a > situation where there is an assignment. The star indicates, that a given > value should be enumerated and assigned to lvalues in order (this applies > also to method argument lists). It doesn't have to be an assignment; you can do: irb(main):003:0> [1,2,*[3,4]] => [1, 2, 3, 4] or: irb(main):004:0> arr = [1,2,3,4] => [1, 2, 3, 4] irb(main):005:0> Hash[*arr] => {1=>2, 3=>4} I like to think of it as the unarr?ay (unary/unarray) operator :-) David -- David A. Black dblack@wobblini.net