https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112013-11-22T23:28:16ZRuby Issue Tracking SystemRuby master - Feature #9140: Allow each_with_index to get start indexhttps://bugs.ruby-lang.org/issues/9140?journal_id=430842013-11-22T23:28:16Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul></ul><p>Unfortunately, it is incompatible because "each_with_index" actually accepts arguments and passes them to "each".</p>
<p>$ ruby -rstringio -e 'StringIO.new("foo|bar|baz").each_with_index("|") {|s, i| p [s, i] }'<br>
["foo|", 0]<br>
["bar|", 1]<br>
["baz", 2]</p>
<p>$ ruby -rstringio -e 'StringIO.new("foo|bar|baz").each("|").with_index(1) {|s, i| p [s, i] }'<br>
["foo|", 1]<br>
["bar|", 2]<br>
["baz", 3]</p>
<p>When I made a proposal to make "with_index" accept an offset, matz determined to leave "each_with_index" as it is.</p>
<p>--<br>
Yusuke Endoh <a href="mailto:mame@tsg.ne.jp" class="email">mame@tsg.ne.jp</a></p> Ruby master - Feature #9140: Allow each_with_index to get start indexhttps://bugs.ruby-lang.org/issues/9140?journal_id=430852013-11-22T23:56:52Zrosenfeld (Rodrigo Rosenfeld Rosas)rr.rosas@gmail.com
<ul></ul><p>This is interesting because I noticed the *args in the documentation but it wasn't documented what it means. So I tried it but in a different context (adapting from your example):</p>
<p>%w(foo bar baz).each_with_index("|") {|s, i| p [s, i] }<br>
ArgumentError: wrong number of arguments (1 for 0)<br>
from (irb):3:in <code>each' from (irb):3:in </code>each_with_index'<br>
from (irb):3<br>
from /home/rodrigo/.rvm/rubies/ruby-2.0.0-p353/bin/irb:12:in `'</p>
<p>That's why I assumed it didn't accept any arguments.</p> Ruby master - Feature #9140: Allow each_with_index to get start indexhttps://bugs.ruby-lang.org/issues/9140?journal_id=430862013-11-23T00:02:10Zrosenfeld (Rodrigo Rosenfeld Rosas)rr.rosas@gmail.com
<ul></ul><p>Actually, it explains but I missed an example :) I do example driven development ;)</p> Ruby master - Feature #9140: Allow each_with_index to get start indexhttps://bugs.ruby-lang.org/issues/9140?journal_id=430872013-11-23T00:05:20Zrosenfeld (Rodrigo Rosenfeld Rosas)rr.rosas@gmail.com
<ul></ul><p>By the way, feel free to reject this ticket then. I only created it because I thought it would be backwards compatible.</p> Ruby master - Feature #9140: Allow each_with_index to get start indexhttps://bugs.ruby-lang.org/issues/9140?journal_id=431052013-11-23T21:23:21Zzzak (zzak _)
<ul></ul><p>So is this a doc bug?</p>
<blockquote>
<p>On Nov 23, 2013, at 12:05 AM, "rosenfeld (Rodrigo Rosenfeld Rosas)" <a href="mailto:rr.rosas@gmail.com" class="email">rr.rosas@gmail.com</a> wrote:</p>
<p>Issue <a class="issue tracker-2 status-6 priority-4 priority-default closed" title="Feature: Allow each_with_index to get start index (Rejected)" href="https://bugs.ruby-lang.org/issues/9140">#9140</a> has been updated by rosenfeld (Rodrigo Rosenfeld Rosas).</p>
<a name="By-the-way-feel-free-to-reject-this-ticket-then-I-only-created-it-because-I-thought-it-would-be-backwards-compatible"></a>
<h2 >By the way, feel free to reject this ticket then. I only created it because I thought it would be backwards compatible.<a href="#By-the-way-feel-free-to-reject-this-ticket-then-I-only-created-it-because-I-thought-it-would-be-backwards-compatible" class="wiki-anchor">¶</a></h2>
<p>Feature <a class="issue tracker-2 status-6 priority-4 priority-default closed" title="Feature: Allow each_with_index to get start index (Rejected)" href="https://bugs.ruby-lang.org/issues/9140">#9140</a>: Allow each_with_index to get start index<br>
<a href="https://bugs.ruby-lang.org/issues/9140#change-43087" class="external">https://bugs.ruby-lang.org/issues/9140#change-43087</a></p>
<p>Author: rosenfeld (Rodrigo Rosenfeld Rosas)<br>
Status: Open<br>
Priority: Normal<br>
Assignee: matz (Yukihiro Matsumoto)<br>
Category: lib<br>
Target version:</p>
<p>Is it possible for array.each_with_index(1){|el, i| ... } to be equivalent to array.each.with_index(1){...}?</p>
<p>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.</p>
<p>--<br>
<a href="http://bugs.ruby-lang.org/" class="external">http://bugs.ruby-lang.org/</a></p>
</blockquote> Ruby master - Feature #9140: Allow each_with_index to get start indexhttps://bugs.ruby-lang.org/issues/9140?journal_id=431162013-11-24T02:05:09Zrosenfeld (Rodrigo Rosenfeld Rosas)rr.rosas@gmail.com
<ul></ul><p>There's no bug. Just reject this feature request.</p> Ruby master - Feature #9140: Allow each_with_index to get start indexhttps://bugs.ruby-lang.org/issues/9140?journal_id=431172013-11-24T02:11:43Zkosaki (Motohiro KOSAKI)kosaki.motohiro@gmail.com
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Rejected</i></li></ul>