Issue #9140 has been updated by mame (Yusuke Endoh).


Unfortunately, it is incompatible because "each_with_index" actually accepts arguments and passes them to "each".

  $ ruby -rstringio -e 'StringIO.new("foo|bar|baz").each_with_index("|") {|s, i| p [s, i] }'
  ["foo|", 0]
  ["bar|", 1]
  ["baz", 2]

  $ ruby -rstringio -e 'StringIO.new("foo|bar|baz").each("|").with_index(1) {|s, i| p [s, i] }'
  ["foo|", 1]
  ["bar|", 2]
  ["baz", 3]

When I made a proposal to make "with_index" accept an offset, matz determined to leave "each_with_index" as it is.

-- 
Yusuke Endoh <mame / tsg.ne.jp>
----------------------------------------
Feature #9140: Allow each_with_index to get start index
https://bugs.ruby-lang.org/issues/9140#change-43084

Author: rosenfeld (Rodrigo Rosenfeld Rosas)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: lib
Target version: 


Is it possible for array.each_with_index(1){|el, i| ... } to be equivalent to array.each.with_index(1){...}?

Sometimes the application-domain index starts with 1, not 0. Currently each_with_index doesn't accept any arguments, so it wouldn't be backward incompatible if the start index defaults to 0.


-- 
http://bugs.ruby-lang.org/