map is an alias to collect . It basically returns an array by performing some operation on every item in the given collection. It expects a block containing the operation.
[1, 2, 3, 4].map {|number| number ** 2}
# [1, 4, 9, 16]
In the above example, note that the result has same number of elements as given array.
The block parameter to map / collect is optional and if omitted, collect / map uses this implied block: {|item| item}, which returns the same array.
Posted by Sandheep to Sandheep's deck (2013-04-26 14:19)