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

ruby-changes:42048

From: akr <ko1@a...>
Date: Tue, 15 Mar 2016 21:53:12 +0900 (JST)
Subject: [ruby-changes:42048] akr:r54122 (trunk): * enum.c (enum_inject): Consider redefinition of Fixnum#+.

akr	2016-03-15 21:53:06 +0900 (Tue, 15 Mar 2016)

  New Revision: 54122

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

  Log:
    * enum.c (enum_inject): Consider redefinition of Fixnum#+.
      [ruby-dev:49510] [Bug#12178] Reported by usa.

  Modified files:
    trunk/ChangeLog
    trunk/enum.c
    trunk/test/ruby/test_enum.rb
Index: test/ruby/test_enum.rb
===================================================================
--- test/ruby/test_enum.rb	(revision 54121)
+++ test/ruby/test_enum.rb	(revision 54122)
@@ -184,6 +184,18 @@ class TestEnumerable < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_enum.rb#L184
     assert_equal(nil, @empty.inject() {9})
   end
 
+  def test_inject_array_plus
+    assert_separately([], <<-"end;")
+      class Fixnum
+        undef :+
+        def +(x)
+          0
+        end
+      end
+      assert_equal(0, [1,2,3].inject(:+), "[ruby-dev:49510] [Bug#12178]")
+    end;
+  end
+
   def test_partition
     assert_equal([[1, 3, 1], [2, 2]], @obj.partition {|x| x % 2 == 1 })
     cond = ->(x, i) { x % 2 == 1 }
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 54121)
+++ ChangeLog	(revision 54122)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Mar 15 21:38:28 2016  Tanaka Akira  <akr@f...>
+
+	* enum.c (enum_inject): Consider redefinition of Fixnum#+.
+	  [ruby-dev:49510] [Bug#12178] Reported by usa.
+
 Tue Mar 15 20:32:57 2016  Tanaka Akira  <akr@f...>
 
 	* enum.c (enum_inject): Implement the specialized code for :+ operator
Index: enum.c
===================================================================
--- enum.c	(revision 54121)
+++ enum.c	(revision 54122)
@@ -719,7 +719,8 @@ enum_inject(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/enum.c#L719
             i = 0;
         }
         id = SYM2ID(op);
-        if (id == idPLUS && FIXNUM_P(v)) {
+        if (id == idPLUS && FIXNUM_P(v) &&
+            rb_method_basic_definition_p(rb_cFixnum, idPLUS)) {
             long n = FIX2LONG(v);
             while (i < RARRAY_LEN(obj)) {
                 VALUE e = RARRAY_AREF(obj, i);

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

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