public Method

Array.each

array.each {|item| block }      array

Calls block once for each element in self, passing that element as a parameter.

a = [ "a", "b", "c" ]
a.each {|x| print x, " -- " }

produces:

a -- b -- c --

Source Code

/*
*  call-seq:
*     array.each {|item| block }   ->   array
*  
*  Calls <i>block</i> once for each element in <i>self</i>, passing that
*  element as a parameter.
*     
*     a = [ "a", "b", "c" ]
*     a.each {|x| print x, " -- " }
*     
*  produces:
*     
*     a -- b -- c --
*/

VALUE
rb_ary_each(ary)
   VALUE ary;
{
   long i;

   for (i=0; i<RARRAY(ary)->len; 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.