Block Conversion Operator
The block conversion operator (&
) is used to convert a proc into a block.
> [1,2,3,4].map(&->(x) { x * x })
=> [1, 4, 9, 16]
We can also do something called "Symbol to Proc" where a symbol referencing a method is converted to a proc which is then converted to a block argument.
> [1,2,3,4].map(&:*)
=> [1, 4, 9, 16]
> %w[one two three].map(&:upcase)
=> ["ONE", "TWO", "THREE"]