Dominik Honnef
1/30/2008 9:49:00 PM
On [Thu, 31.01.2008 06:42], Sebastian Hungerecker wrote:
> Dominik Honnef wrote:
> > > p *1..100
> >
> > Would you be so gentle and explain this piece of code to me?
> > [...] isn't * a binary operator? I
>
>
> * can be a binary operator, yes, but here it is the unary, prefix
> splat-operator which takes an array or any object that responds to
> to_a and turns it into a list of arguments:
> foo(*[:la,:li,:lu]) becomes foo(:la,:li,:lu)
> p *1..5 becomes p 1,2,3,4,5
>
>
> HTH,
> Sebastian
> --
> Jabber: sepp2k@jabber.org
> ICQ: 205544826
Ah, yeah of course... I totally forgot about that.
If it had been puts(*[1,2,3...]) I wouldnt have asked that question :/
Actually, I'm using this feature a lot in my codes. But didn't know it takes any object,
which responds to #to_a
Thank you :)
(Okay, I forgot, that puts can take multiple arguments, too. Sometimes, Ruby is just too easy)
--
Dominik Honnef