Skip to content
instance method

Array#map

[U] () { (Elem item) -> U } -> ::Array[U]
() -> ::Enumerator[Elem, ::Array[untyped]]
map {|element| ... } → new_array
map → new_enumerator

Alias of #collect

With a block given, calls the block with each element of self; returns a new array whose elements are the return values from the block:

Example
a = [:foo, 'bar', 2]
a1 = a.map {|element| element.class }
a1 # => [Symbol, String, Integer]

With no block given, returns a new Enumerator.

Related: collect!; see also Methods for Converting.

See also #collect #map! #length #last also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0