Ruby has the syntax feature like
& with many use scenario. I combined some interesting posts I have found.
Let’s start from the basics. Ruby has the following syntax feature:
It works because Ruby expands
&:name.to_proc and adds method to_proc for the Symbol class
& operator may take any proc object or the objects that can be converted to proc by to_proc method.
You can use the self’s methods
You can supply arguments to
& syntax too. (ref )
As we saw above the
proc object could be taken from the method of an instance so for the simple arithmetic this works too.
Compiled from the following posts