aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-15 12:53:06 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-15 12:53:06 +0000
commit32674b167bddc0d737c38f84722986b0f228b44b (patch)
treed40b3fa2084e3407067b40e4865667a057464fa9
parentda9b5e9c8910435d18b466e2f6cd96b27548bd95 (diff)
downloadruby-32674b167bddc0d737c38f84722986b0f228b44b.tar.gz
* enum.c (enum_inject): Consider redefinition of Fixnum#+.
[ruby-dev:49510] [Bug#12178] Reported by usa. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54122 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--enum.c3
-rw-r--r--test/ruby/test_enum.rb12
3 files changed, 19 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index f526654ce0..cbf7794614 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Tue Mar 15 21:38:28 2016 Tanaka Akira <akr@fsij.org>
+
+ * 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@fsij.org>
* enum.c (enum_inject): Implement the specialized code for :+ operator
diff --git a/enum.c b/enum.c
index ba444e33c6..951e30ab32 100644
--- a/enum.c
+++ b/enum.c
@@ -719,7 +719,8 @@ enum_inject(int argc, VALUE *argv, VALUE obj)
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);
diff --git a/test/ruby/test_enum.rb b/test/ruby/test_enum.rb
index 6162830b69..3dfbd26929 100644
--- a/test/ruby/test_enum.rb
+++ b/test/ruby/test_enum.rb
@@ -184,6 +184,18 @@ class TestEnumerable < Test::Unit::TestCase
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 }