[前][次][番号順一覧][スレッド一覧]

ruby-changes:38775

From: marcandre <ko1@a...>
Date: Sat, 13 Jun 2015 00:45:51 +0900 (JST)
Subject: [ruby-changes:38775] marcandRe: r50856 (trunk): * lib/prime.rb: Fix with_object with no block given

marcandre	2015-06-13 00:45:44 +0900 (Sat, 13 Jun 2015)

  New Revision: 50856

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50856

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

  Modified files:
    trunk/ChangeLog
    trunk/lib/prime.rb
    trunk/test/test_prime.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 50855)
+++ ChangeLog	(revision 50856)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Jun 13 00:45:06 2015  Marc-Andre Lafortune  <ruby-core@m...>
+
+	* lib/prime.rb: Fix with_object with no block given
+
 Sat Jun 13 00:44:59 2015  Marc-Andre Lafortune  <ruby-core@m...>
 
 	* lib/prime.rb: Have with_index accept an offset parameter.
Index: lib/prime.rb
===================================================================
--- lib/prime.rb	(revision 50855)
+++ lib/prime.rb	(revision 50856)
@@ -281,7 +281,7 @@ class Prime https://github.com/ruby/ruby/blob/trunk/lib/prime.rb#L281
 
     # 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
Index: test/test_prime.rb
===================================================================
--- test/test_prime.rb	(revision 50855)
+++ test/test_prime.rb	(revision 50856)
@@ -97,6 +97,15 @@ class TestPrime < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/test_prime.rb#L97
     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)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]