Method: Array#each
- Defined in:
- array.c
#each {|item| ... } ⇒ Array #each ⇒ Enumerator
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 --
2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 |
# File 'array.c', line 2128
VALUE
rb_ary_each(VALUE ary)
{
long i;
ary_verify(ary);
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;
}
|