------ art_57027_18889904.1171553641274 Content-Type: text/plain; charset=WINDOWS-1252; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline ok and its like .... *a = 9 a << 5 b = *a # => [9,5] is there any relation in this n above ? 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. ;) > > Another way to look at it, which I think covers all of the above > cases, is: > > *x equals [x] without the [] > > So: > > *a = 9 # a without the [] is 9, so a == [9] > *b = a # b without the [] is [9], so b == [[9]] > b = *a # b == [9] without the [], so b == 9 > > > That's why I call it the "unary unarray" operator. > > > 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) > -- sur http://expressica.com ------ art_57027_18889904.1171553641274--