From: Mirko Viviani Date: 2009-07-23T18:23:11+09:00 Subject: Re: Ruby "star".... what's it? --0016367b6e3028ab60046f5c0941 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Sorry, Complete code was like this x, *xs =3D *myarray after executing, x is 1 and xs [2,3,4,5,6,6] ..... :o 2009/7/23 Max Williams > Mirko Viviani wrote: > > Hi everybody. > > What means this snippet of code? Why use the "star" ? > > > > myarray =3D [1,2,3,4,5,6,6] > > qa =3D *myarray > > > > Thank you. > > In this example it doesn't really do anything, i think. Normally you > would use the * in an argument list, in a method definition, to > effectively say 'pull all arguments after this into a single array', eg > > >> def foo(mainarg, *otherargs) > >> puts mainarg.inspect > >> puts otherargs.inspect > >> end > =3D> nil > >> foo(1,2,3,4,5,6) > 1 > [2, 3, 4, 5, 6] > =3D> nil > > In this sense it's like * in a regular expression, meaning 'any number > of arguments'. That's how i understand it anyway, a more precise > description will probably be forthcoming :) > -- > Posted via http://www.ruby-forum.com/. > > --=20 -- Mirko Viviani -- GPG-PGP Public Key: 0xE4E8FAB1 Fingerprint: 14D3 A373 E926 7737 DF32 502B A4C4 1CE2 E4E8 FAB1 *********************************************** "=93Machines take me by surprise with great frequency.=94 A. Turing --0016367b6e3028ab60046f5c0941--