Ruby Language Map


Example

Returns the changed object, but the original object remains as it was. For example:

arr = [1, 2, 3]
arr.map { |i| i + 1 } # => [2, 3, 4]
arr # => [1, 2, 3]

map! changes the original object:

arr = [1, 2, 3]
arr.map! { |i| i + 1 } # => [2, 3, 4]
arr # => [2, 3, 4]

Note: you can also use collect to do the same thing.