From: sur max Date: 2007-02-16T01:40:58+09:00 Subject: Re: is it behaving strange ? ------=_Part_57751_31491045.1171557653959 Content-Type: text/plain; charset=WINDOWS-1252; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Thats pretty known. And even this too... a =3D 2,3,4,5,6 # =3D> [2,3,4,5,6] b, =3D a --- now this is beauty b # =3D> 2 b,c =3D a b # =3D> 2 c # =3D> 3 and so... b,c,d =3D a but still didnt get clear .... is it like we can use *a for assigning to some other var ONLY ? On 2/15/07, hemant wrote: > > On 2/15/07, sur max wrote: > > ok and its like .... > > > > *a =3D 9 > > remember a would become an array here.because as explained above,if > lvalue is prefixed with asterisk, then rvalue is collected and > assigned to lvalue as an array. > > > a << 5 > > append 5 to a (which is an array) > > > b =3D *a # =3D> [9,5] > > is there any relation in this n above ? > > Now, above is pretty standard ruby behaviour, it has nothing to do > with * operator, as usual * extracts the values from a(which was an > array). > > For example: > > irb(main):062:0> b =3D 9,5 > [9, 5] > irb(main):063:0> b > [9, 5] > irb(main):064:0> b,c =3D 9,5 > [9, 5] > irb(main):065:0> b > 9 > irb(main):066:0> c > 5 > > > > > > > > On 2/15/07, dblack@wobblini.net wrote: > > > > > > 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 > > > 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 th= e > > > > 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 > > > > > > -- > > > 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 > > > > > -- > gnufied > ----------- > There was only one Road; that it was like a great river: its springs > were at every doorstep, and every path was its tributary. > http://people.inxsasia.com/~hemant > > --=20 sur http://expressica.com ------=_Part_57751_31491045.1171557653959--