Artur Merke
11/3/2006 10:58:00 AM
Farrel Lifson schrieb:
> On 03/11/06, Artur Merke <am@artbot.de> wrote:
> > Just a short question concerning the ruby lexer/parser
> >
> > irb(main):001:0> a=1
> > => 1
> > irb(main):002:0> a.to_f * 10.0 #space before and after '*'
> > => 10.0
> > irb(main):003:0> a.to_f*10.0 #no space before and after '*'
> > => 10.0
> >
> > irb(main):005:0* a.to_f *10.0 #space before '*' and no space after
> > '*'
> > ArgumentError: wrong number of arguments (1 for 0)
> > from (irb):5:in `to_f'
> > from (irb):5
> >
> > so why does ruby think *10.0 would be an argument to .to_f?
> >
> > In my opinion the ruby lexer sould recognize '*' as an operator, no
> > spacing should
> > have any influence on this behavior ...
> >
> >
> > Artur
>
> * can have dual meanings. It can be a method call on an object (in
> your first two examples) or it can act as the 'splat' operator when it
> directly preceeds an object.
>
> Farrel
yes, you are right. I was just suprised, that it only is a problem
after a method invocation (as 'a *10' works fine),
but this behavior seems to be enforced by ruby's slack handling of
parentheses ...
Artur