Suppose you have the following formula. Convert each element to uppercase in the block and store it in an array.
['a', 'b', 'c'].map{|s| s.upcase } #=> ["A", "B", "C"]
You can easily follow the above example using array.map (&: method).
['a', 'b', 'c'].map(&:upcase) # => ["A", "B", "C"]
Recommended Posts