map!()
public
Invokes the block once for each element of
self, replacing the element with the value returned by
block. See also Enumerable#collect.
a = [ "a", "b", "c", "d" ]
a.collect! {|x| x + "!" }
a
Show source
/*
* call-seq:
* array.collect! {|item| block } -> array
* array.map! {|item| block } -> array
*
* Invokes the block once for each element of _self_, replacing the
* element with the value returned by _block_.
* See also <code>Enumerable#collect</code>.
*
* a = [ "a", "b", "c", "d" ]
* a.collect! {|x| x + "!" }
* a
*/
static VALUE
rb_ary_collect_bang(ary)
VALUE ary;
{
long i;
RETURN_ENUMERATOR(ary, 0, 0);
rb_ary_modify(ary);
for (i = 0; i < RARRAY(ary)->len; i++) {
rb_ary_store(ary, i, rb_yield(RARRAY(ary)->ptr[i]));
}
return ary;
}