As we know, there are several way of Proc calling in Ruby 1.9
f =->n {[:hello, n]}
p f[:ruby] # => [:hello, :ruby]
p f.call(:ruby) # => [:hello, :ruby]
p f.(:ruby) # => [:hello, :ruby]
p f === :ruby # => [:hello, :ruby]
I am curious, what is more ‘natural’ way of calling Proc? ‘Natural’, probably, means more Computer Science – like way.
The second option is by far the most used.
It makes it more similar to a standard method. Also, some libraries actually rely on duck typing when validating arguments checking the availability of the
#callmethod. In this case, using#callensures you can provide a lambda or any other object (including a Class) that responds to#call.Rackmiddlewares are a great example of this convention. The basic middleware can be a lambda, or you can supply more complex logic by using classes.