aboutsummaryrefslogtreecommitdiffstats
path: root/lib/prime.rb
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-06-12 15:45:22 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-06-12 15:45:22 +0000
commit6b37276ba33236ae19fbdaf6cf69e629b90fab07 (patch)
treedce222092b9202f394cdff1c6509637185f991a4 /lib/prime.rb
parent33c2a9de6f2197ac0a67f5fde083647741d25618 (diff)
downloadruby-6b37276ba33236ae19fbdaf6cf69e629b90fab07.tar.gz
* 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
Diffstat (limited to 'lib/prime.rb')
-rw-r--r--lib/prime.rb10
1 files changed, 9 insertions, 1 deletions
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)