On 2/15/07, sur max <sur.max / gmail.com> wrote:
> Thats pretty known.
> And even this too...

Again, I am sorry to bore you with little known things. ;)

> a = 2,3,4,5,6  # => [2,3,4,5,6]
>
> b, = a   --- now this is beauty
> b # => 2
> b,c = a
> b # => 2
> c # => 3
> and so...
> b,c,d = a
>
> but still  didnt get clear .... is it like we can use *a for assigning to
> some other var ONLY ?

I would like to think so, thats why we got syntax error exception
tossed at our face when we do:

*a = 9
*a

I guess ruby interpretor is doing tough job of differentiating splat
from multiplication operator and it decided to not allow you to do
that.

However, you can very well do

a = 9
+a
++a
-a

Again, I might be stating the obvious. ;)



> On 2/15/07, hemant <gethemant / gmail.com> wrote:
> >
> > On 2/15/07, sur max <sur.max / gmail.com> wrote:
> > > ok and its like ....
> > >
> > > *a = 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 = *a # => [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 = 9,5
> > [9, 5]
> > irb(main):063:0> b
> > [9, 5]
> > irb(main):064:0> b,c = 9,5
> > [9, 5]
> > irb(main):065:0> b
> > 9
> > irb(main):066:0> c
> > 5
> >
> >
> >
> >
> > >
> > > 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
> > >
> >
> >
> > --
> > 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
> >
> >
>
>
> --
> 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