Symbol to Proc
TL;DR:
- Symbol to Proc is Awesome!
- You can use it as a shorthand
array.each(&:method_name)
Lets say we have array of names and we want to transform the names to upcase. One way to do this is to use the map method.
You could shorten this by using symbol to proc. Let just look at the code and than see what is happening under the hood.
:upcase
is a symbol and when we ad &
infront of the symbol the .to_proc
method is called on the symbol.
Knowing this we can play around and monkey patch the Symbol class.
If we wanted to reimplement rubys default behaviour we could write the code something like this