Ruby 2.7 adds experimental shorthand operator for
This allows method object access using
This feature was first proposed 3 years ago and an experimental version of the feature is finally out for use on Ruby 2.7
You can follow more discussion and alternatives to this syntax here.
We can access methods on an Object using the
method call on an Object.
We can use this method object returned from
to be passed around,
which can then be called elsewhere.
In the example above we are passing method object,
to the map method.
We are passing a reference to the method here to be called,
instead of actually invoking it,
This is a common pattern, for example:
Method shorthand operator
As you can see, calling
Object.method(:method_name) can be too verbose.
Ruby 2.7 introduces an experimental feature to access methods in a shorthand way.
Where it can be accessed
The method call is available on
Object it is made available on Object instances, Classes, Modules, etc.