instance method
Array#map!
() { (Elem item) -> Elem } -> self
() -> ::Enumerator[Elem, self]
map! {|element| ... } → self
map! → new_enumerator
array.c
View on GitHub ↗
static VALUE
rb_ary_collect_bang(VALUE ary)
{
long i;
RETURN_SIZED_ENUMERATOR(ary, 0, 0, ary_enum_length);
rb_ary_modify(ary);
for (i = 0; i < RARRAY_LEN(ary); i++) {
rb_ary_store(ary, i, rb_yield(RARRAY_AREF(ary, i)));
}
return ary;
}
Alias of #collect!
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.