Skip to content
instance method

Enumerable#map

[U] () { (Elem arg0) -> U } -> ::Array[U]
() -> ::Enumerator[Elem, ::Array[untyped]]
map {|element| ... } → array
map → enumerator

Alias of #collect

Returns an array of objects returned by the block.

With a block given, calls the block with successive elements; returns an array of the objects returned by the block:

Example
(0..4).map {|i| i*i }                               # => [0, 1, 4, 9, 16]
{foo: 0, bar: 1, baz: 2}.map {|key, value| value*2} # => [0, 2, 4]

With no block given, returns an Enumerator.

See also #collect #lazy #max #inject also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0