APIdock / Ruby
/
method

map!

ruby latest stable - Class: Array
map!()
public

Invokes the given block once for each element of self, replacing the element with the value returned by the block.

See also Enumerable#collect.

If no block is given, an Enumerator is returned instead.

a = [ "a", "b", "c", "d" ]
a.map!  {|x| x + "!" }
a #=> [ "a!", "b!", "c!", "d!" ]
a.collect! .with_index {|x, i| x[0...i] }
a #=> ["", "b", "c!", "d!"]
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;
}

AltStyle によって変換されたページ (->オリジナル) /