Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Enumerator#with_index

(?::Integer offset) { (E arg0, ::Integer arg1) -> untyped } -> R
(?::Integer offset) -> ::Enumerator[[ E, ::Integer ], R]
e.with_index(offset = 0) {|(*args), idx| ... }
e.with_index(offset = 0)

Iterates the given block for each element with an index, which starts from offset. If no block is given, returns a new Enumerator that includes the index, starting from offset

offset

the starting index to use

See also #size #with_object #rewind also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0