From dd8f914d3ba6ffb256376e724b3e249facfdc888 Mon Sep 17 00:00:00 2001 From: marcandre Date: Fri, 12 Jun 2015 15:45:22 +0000 Subject: * lib/prime.rb: Have with_index accept an offset parameter. Based on patch by T Yamada. [#11007] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50854 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/prime.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'lib/prime.rb') diff --git a/lib/prime.rb b/lib/prime.rb index d361e96720..757538db79 100644 --- a/lib/prime.rb +++ b/lib/prime.rb @@ -269,7 +269,15 @@ class Prime end # see +Enumerator+#with_index. - alias with_index each_with_index + def with_index(offset = 0) + return enum_for(:with_index, offset) unless block_given? + return each_with_index(&proc) if offset == 0 + + each do |prime| + yield prime, offset + offset += 1 + end + end # see +Enumerator+#with_object. def with_object(obj) -- cgit v1.2.3