Quoting Sean O'Halpin <[EMAIL PROTECTED]>:

> It gets worse ;)
>
> There is also the case where [] can be a synonym for Proc#call,
> e.g.
>
> foo = proc {|x| x*x }
>
> foo [2] #=> 4

The difference between an array and a proc doesn't matter, at least
not when parsing.  [] in such a context is simply a method and
dispatched as such.

The discriminator is whether foo is determined to be a local
variable or a method.

If foo is a method, foo [2] parses as:

(fcall foo
  (array
    (array
      (lit #<2>))))

If foo is a local variable, foo [2] parses as:

(call
  (lvar foo) []
  (array
    (lit #<2>)))

So, yet another place where this local variable versus method name
thing really matters.

-mental
_______________________________________________
Rubygrammar-grammarians mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rubygrammar-grammarians

Reply via email to