This email is really clear. Thanks!


2014-07-20 23:56 GMT-03:00 Matthew Kerwin <matthew / kerwin.net.au>:

> On 21 July 2014 12:09, Juanjo Conti <jjconti / gmail.com> wrote:
>
>>  
>> I got it!
>>
>> A can't be a method, because it's upcase!
>>
>>
> Note quite, upcase methods are allowed; see:
> http://www.ruby-doc.org/core-2.1.2/Kernel.html#method-i-Integer  Try
> running:  Integer -4.2
>
> Consider this code:
>
>     a + 1
>     # we've never seen 'a =' before, so we assume it's a function
>     # first call a(), then on the resulting object call .+(1)
>     # same as: a().+(1)
>
>     a +1
>     # <word> <space> <plus> <any> = function call
>     # same as: a(1.+@())
>
>     C + 1
>     # C starts with a capital, so we assume it's a const
>     # same as: C.+(1)
>
>      C +1
>     # <word> <space> <plus> <any> = function call
>     # same as: C(1.+@())
>
>     b = 2
>     b + 1
>     # we *have* seen 'b =' before, so we know it's an lvar
>     # same as: b.+(1)
>
>     b +1
>     # <lvar> <space> <plus> <any> = *not* function call
>     # same as "b + 1": b.+(1)
>
>
> You could do a similar thing with @x, @@y, or $z. Thoseare
> unambiguously variable names, so they'd never be interpreted as a function.
>
>
> Have a think about what's going on here, if it helps:
>
>  irb(main):001:0> def a(*args) p [:a, *args]; end
> irb(main):002:0> def b(*args) p [:b, *args]; end
> irb(main):003:0> def C(*args) p [:C, *args]; end
> irb(main):004:0> b = 1
> irb(main):005:0> C = 99
> irb(main):006:0> a +1
> [:a, 1]
> => [:a, 1]  # a(1.+@())
> irb(main):007:0> b +1
> => 2  # b.+(1)
> irb(main):008:0> C +1
> [:C, 1]
> => [:C, 1]  # C(1.+@)
> irb(main):009:0> a + 1
> [:a]
> TypeError: no implicit conversion of Fixnum into Array
>  from (irb):9:in `+'
>  from (irb):9
> from /usr/local/bin/irb-trunk:11:in `<main>'
> # a().+(1)
> irb(main):010:0> b + 1
> => 2  # b.+(1)
> irb(main):011:0> C + 1
> => 100  # C.+(1)
>
> 
>
>
> --
>   Matthew Kerwin
>   http://matthew.kerwin.net.au/
>



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