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_f10.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 …
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.
irb(main):005:0* a.to_f 10.0 #space before '’ and no space after
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.