You need some way to distinguish a Proc call from transmitting it.
In Python and ECMAScript, this is simple: with parentheses this is a call, without it there is none. In Ruby, parenthesis exclusion is also a call, so there must be some other way of distinguishing it.
In Ruby 1.8, Proc#call and its alias Proc#[] serve this distinction. Starting with Ruby 1.9, obj.(arg) is the syntax sugar for obj.call(arg) and Proc#() also an alias for Proc#call .
So you can call Proc as follows:
- foo.call (1, 2, 3)
- foo [1, 2, 3]
- phew. (1, 2, 3)
And you can even define () for your own classes.
By the way, the same problem is why you should use a method method to get a method object.
Jรถrg W Mittag
source share