Right, thanks. But why that is not happening with a +"B"?


2014-07-19 22:45 GMT-03:00 Ryan Davis <ryand-ruby / zenspider.com>:

>
> On Jul 19, 2014, at 17:02, Juanjo Conti <jjconti / gmail.com> wrote:
>
> > 2.1.2 :025 > A +B
> > NoMethodError: undefined method `+@' for "B":String
> >     from (irb):25
> >     from /home/juanjo/.rvm/rubies/ruby-2.1.2/bin/irb:11:in `<main>'
>
> >> RubyParser.new.parse "A + B"
> => s(:call, s(:const, :A), :+, s(:const, :B))
>
> >> RubyParser.new.parse "A +B"
> => s(:call, nil, :A, s(:call, s(:const, :B), :+@))
>
> So it is seeing "A(+B)" where "+" is a unary method, much like "-".
>
> Same as if you typed `N +4`, it'd see `N(+4)`, call unary + on 4, then
> pass that as an arg to N.
>
>
>


-- 
Juanjo Conti
blog: http://www.juanjoconti.com.ar