From: Robert Dober Date: 2007-02-16T02:42:27+09:00 Subject: Re: is it behaving strange ? On 2/15/07, dblack@wobblini.net wrote: > Hi -- > > On Fri, 16 Feb 2007, hemant wrote: > > > On 2/15/07, sur max wrote: > >> *a = 9 # => [9] > >> a # => [9] > >> *a # => compile error > >> *b=*a # => [9] > >> *b = a # => [[9]] > >> b = a # => [9] > >> b = *a # => 9 ----- this is amazing ? > > > > Splat operator is amazing, but above behaviour can be explained using this: > > > > "If the last lvalue is preceded by an asterisk, all the remaining > > rvalues will be collected and > > assigned to that lvalue as an array. Similarly, if the last rvalue is > > an array, you can > > prefix it with an asterisk, which effectively expands it into its > > constituent values in > > place. (This is not necessary if the rvalue is the only thing on the > > right side�the array > > will be expanded automatically.) > > " > > See, nothing wierd out there. ;) Well I cannot speak for OP but what puzzles me is a=[42] # sorry 9 is not the number ;) *a ==> error # gotta check with 1.9 an 2.0 at home I would think that this expression can/could/should/might perfectly evaluate to 42 look at this other oddity the following code is completely legal and POLS(1) def x *args return *args end (1) in the sense that a,b,c = x 1,2,3 sets a to 1, b to 2 and c to 3 and x is a NOP but return in the last statement is optional, or is it not ;) I know you are not falling into my trap ! I see no reason however why def x *args *args end should not be legal > > Another way to look at it, which I think covers all of the above > cases, is: > > *x equals [x] without the [] unless it causes an error, which is not really very sexy behavior IMHO. > > That's why I call it the "unary unarray" operator. Which is a good mnemonic idea! Very didactic I feel! > > > David > > -- > Q. What is THE Ruby book for Rails developers? > A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black) > (See what readers are saying! http://www.rubypal.com/r4rrevs.pdf) > Q. Where can I get Ruby/Rails on-site training, consulting, coaching? > A. Ruby Power and Light, LLC (http://www.rubypal.com) > Cheers Robert -- We have not succeeded in answering all of our questions. In fact, in some ways, we are more confused than ever. But we feel we are confused on a higher level and about more important things. -Anonymous