Where's this ruby feature documented.and the case of an accidentally discovered feature

So, while doing some random testing in an IRB session, I accidentally
discovered a feature of ruby that is new to me. Apparently, you can call
a
method named “call” by omitting the name of the method you wish to call:

1.9.3-p194 :001 > x = → { puts “Hello, world.” }
=> #<Proc:0x007f820d179710@(irb):1 (lambda)>
1.9.3-p194 :002 > x.()
Hello, world.
=> nil

Or, more explicitly:

1.9.3-p194 :001 > class X
1.9.3-p194 :002?> def call(name)
1.9.3-p194 :003?> puts “Hello, #{name}”
1.9.3-p194 :004?> end
1.9.3-p194 :005?> end
=> nil
1.9.3-p194 :006 > x = X.new
=> #<X:0x007f968b92e6d0>
1.9.3-p194 :007 > x.(“Bob”)
Hello, Bob
=> nil

In all the books, articles, blogs, and tutorials that I’ve read, I don’t
recall any every mentioning this feature anywhere. As soon as I stumbled
on
this feature, I search the Pickaxe book and Google to see if and where
this
feature was documented. No luck.

What I did end up finding was a chunk of example code from the jbuilder
gem’s README that uses this feature:

Specifically, the 3rd line in the first code example:

json.(@message, :created_at, :updated_at)

I’m sure there’s code and examples out there that also use this feature.
However, what I’d really be interested in knowing is just what this
feature
is officially called and where it’s documented (I’m just really OCD and
curious about some things).

Anyone know of the top your head? How long has this feature been in
ruby?
All along? Is it a newer feature?

Thanks for any feedback.

On 06/27/2013 04:24 PM, Kendall G. wrote:

Or, more explicitly:
Hello, Bob

ruby? All along? Is it a newer feature?
It was added in Ruby 1.9. It is mentioned somewhat in passing in the
docs for Proc#call:
Class: Proc (Ruby 1.9.3)

From what I can tell, this syntax just isn’t that popular. I have
definitely never seen it used as a proxy for #call on an object other
than a Proc, although I admit it’s kind of cool.

-Justin

On Thu, Jun 27, 2013 at 11:56 PM, Justin C.
[email protected]wrote:

=> nil
=> #<X:0x007f968b92e6d0>
gem’s README that uses this feature:

a Proc, although I admit it’s kind of cool.

-Justin

Sweet, thanks for the info! Glad to know when it was added and where
it’s
documented.