From: dblack@... Date: 2007-02-16T00:30:20+09:00 Subject: Re: is it behaving strange ? ---2049402039-1105539072-1171553417=:7186 Content-Type: MULTIPART/MIXED; BOUNDARY="-2049402039-1105539072-1171553417=:7186" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. ---2049402039-1105539072-1171553417=:7186 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Hi -- On Fri, 16 Feb 2007, hemant wrote: > On 2/15/07, sur max wrote: >> *a =3D 9 # =3D> [9] >> a # =3D> [9] >> *a # =3D> compile error >> *b=3D*a # =3D> [9] >> *b =3D a # =3D> [[9]] >> b =3D a # =3D> [9] >> b =3D *a # =3D> 9 ----- this is amazing ? > > Splat operator is amazing, but above behaviour can be explained using thi= s: > > "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=97the 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 =3D 9 # a without the [] is 9, so a =3D=3D [9] *b =3D a # b without the [] is [9], so b =3D=3D [[9]] b =3D *a # b =3D=3D [9] without the [], so b =3D=3D 9 That's why I call it the "unary unarray" operator. David --=20 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) ---2049402039-1105539072-1171553417=:7186-- ---2049402039-1105539072-1171553417=:7186--