Skip to content
instance method

Array#collect!

() { (Elem item) -> Elem } -> self
() -> ::Enumerator[Elem, self]
collect! {|element| ... } → self
collect! → new_enumerator

With a block given, calls the block with each element of self and replaces the element with the block’s return value; returns self:

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

With no block given, returns a new Enumerator.

Related: collect; see also Methods for Converting.

See also #collect #combination #clear #compact also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0