APIdock / Ruby
/
method

each

ruby latest stable - Class: Array
each()
public

Calls the given block once for each element in self, passing that element as a parameter. Returns the array itself.

If no block is given, an Enumerator is returned.

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

produces:

a -- b -- c --
VALUE
rb_ary_each(VALUE ary)
{
 long i;
 RETURN_SIZED_ENUMERATOR(ary, 0, 0, ary_enum_length);
 for (i=0; i<RARRAY_LEN(ary); i++) {
 rb_yield(RARRAY_AREF(ary, i));
 }
 return ary;
}

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