From: nobu@... Date: 2015-03-28T03:02:20+00:00 Subject: [ruby-core:68666] [Ruby trunk - Feature #11007] Prime.each.with_index should accept offset Issue #11007 has been updated by Nobuyoshi Nakada. `Kernel#proc` captures the block given to the caller. ~~~ruby def with_index(offset = 0) return enum_for(:with_index) unless block_given? # if offset == 0, use each_with_index, which is faster because of C implementation. return each_with_index(&proc) if offset == 0 each do |prime| yield prime, offset offset += 1 end end ~~~ and `enum = Prime.each` is needed before loop again. It's better to split the test. ---------------------------------------- Feature #11007: Prime.each.with_index should accept offset https://bugs.ruby-lang.org/issues/11007#change-51959 * Author: T Yamada * Status: Open * Priority: Normal * Assignee: Marc-Andre Lafortune ---------------------------------------- I'd like to execute following code: ~~~ Prime.each(10).with_index(1){|e,i| print i,' ',e,"\n" } ~~~ Expected output: ~~~ 1 2 2 3 3 5 4 7 ~~~ I have attached a patch. ---Files-------------------------------- prime.diff (1.09 KB) -- https://bugs.ruby-lang.org/