Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Enumerator::Chain#each
() { (E) -> void } -> self
() -> ::Enumerator[E, self]
obj.each(*args) { |...| ... } → obj
obj.each(*args) → enumerator
enumerator.c
View on GitHub ↗
static VALUE
enum_chain_each(int argc, VALUE *argv, VALUE obj)
{
VALUE enums, block;
struct enum_chain *objptr;
rb_len_t i;
RETURN_SIZED_ENUMERATOR(obj, argc, argv, argc > 0 ? enum_chain_enum_no_size : enum_chain_enum_size);
objptr = enum_chain_ptr(obj);
enums = objptr->enums;
block = rb_block_proc();
for (i = 0; i < RARRAY_LEN(enums); i++) {
objptr->pos = i;
rb_funcall_with_block(RARRAY_AREF(enums, i), id_each, argc, argv, block);
}
return obj;
}
Iterates over the elements of the first enumerable by calling the “each” method on it with the given arguments, then proceeds to the following enumerables in sequence until all of the enumerables are exhausted.
If no block is given, returns an enumerator.