diff --git a/ChangeLog b/ChangeLog index 4104d244cc..ff5ae43c38 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Sat Jun 13 00:45:06 2015 Marc-Andre Lafortune + + * lib/prime.rb: Fix with_object with no block given + Sat Jun 13 00:44:59 2015 Marc-Andre Lafortune * lib/prime.rb: Have with_index accept an offset parameter. diff --git a/lib/prime.rb b/lib/prime.rb index 757538db79..1eed28d914 100644 --- a/lib/prime.rb +++ b/lib/prime.rb @@ -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 diff --git a/test/test_prime.rb b/test/test_prime.rb index 5975336023..d4f056466f 100644 --- a/test/test_prime.rb +++ b/test/test_prime.rb @@ -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)