public Method

Array.map!

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 Enumerable#collect.

a = [ "a", "b", "c", "d" ]
a.collect! {|x| x + "!" }
a             #=>  [ "a!", "b!", "c!", "d!" ]

Source Code

/* 
*  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             #=>  [ "a!", "b!", "c!", "d!" ]
*/

static VALUE
rb_ary_collect_bang(ary)
   VALUE ary;
{
   long i;

   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;
}
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.