------ art_59049_30349876.1171563883130 Content-Type: text/plain; charset=WINDOWS-1252; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline def a *args *args end is very much illegal .... giving compile error and with return keyword it works very fine. I am still feeling that point(s) still lasts Again i am repeating the same old story .... *a = 9 # i like this number :) b = *a # => 9 ------- mind it, it is Fixnum here it seems true "*x equals [x] without the []" a << 5 b = *a # => [9,5] ------- an Array here it seems false "*x equals [x] without the []" moreover *a # => compile error is it strange behavior ? or pretty digestible ? :) On 2/15/07, Robert Dober <robert.dober / gmail.com> wrote: > > On 2/15/07, dblack / wobblini.net <dblack / wobblini.net> wrote: > > Hi -- > > > > On Fri, 16 Feb 2007, hemant wrote: > > > > > On 2/15/07, sur max <sur.max / gmail.com> 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ÍÕhe 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. > > > <snip> > > 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 > > -- sur http://expressica.com ------ art_59049_30349876.1171563883130--