Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Enumerator::Lazy#with_index
(?::Integer offset) { (E arg0, ::Integer arg1) -> untyped } -> R
(?::Integer offset) -> ::Enumerator[[ E, ::Integer ], R]
lazy.with_index(offset = 0) {|(*args), idx| block }
lazy.with_index(offset = 0)
enumerator.c
View on GitHub ↗
static VALUE
lazy_with_index(int argc, VALUE *argv, VALUE obj)
{
VALUE memo;
rb_scan_args(argc, argv, "01", &memo);
if (NIL_P(memo))
memo = LONG2NUM(0);
return lazy_with_index_from(obj, memo);
}
If a block is given, returns a lazy enumerator that will iterate over the given block for each element with an index, which starts from offset, and returns a lazy enumerator that yields the same values (without the index).
If a block is not given, returns a new lazy enumerator that includes the index, starting from offset.
offset-
the starting index to use