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 --
1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 |
# File 'array.c', line 1808
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;
}
|