1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/prime.rb: Fix with_object with no block given

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50856 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
marcandre 2015-06-12 15:45:44 +00:00
parent 2689fd677c
commit 5b78e48c31
3 changed files with 14 additions and 1 deletions

View file

@ -1,3 +1,7 @@
Sat Jun 13 00:45:06 2015 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
* lib/prime.rb: Fix with_object with no block given
Sat Jun 13 00:44:59 2015 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
* lib/prime.rb: Have with_index accept an offset parameter.

View file

@ -281,7 +281,7 @@ class Prime
# see +Enumerator+#with_object.
def with_object(obj)
return enum_for(:with_object) unless block_given?
return enum_for(:with_object, obj) unless block_given?
each do |prime|
yield prime, obj
end

View file

@ -97,6 +97,15 @@ class TestPrime < Test::Unit::TestCase
end
end
def test_enumerator_with_object
object = Object.new
enum = Prime.each
enum.with_object(object).each do |p, o|
assert_equal object, o
break
end
end
def test_default_instance_does_not_have_compatibility_methods
assert !Prime.instance.respond_to?(:succ)
assert !Prime.instance.respond_to?(:next)