summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-15 06:27:30 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-15 06:27:30 +0000
commit723cee93c481e62579e5353d9128e1538381cbab (patch)
treedcd59219045d5b5ad7dc913b520239d47b6f2ca6
parente02c5f346fd54d9183aaba3eab517bcf7a0613f1 (diff)
enum.c: nil if no iteration
* enum.c (enum_inject): return nil if no iteration, instead of Qundef. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47928 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--enum.c1
-rw-r--r--test/ruby/test_enum.rb1
2 files changed, 2 insertions, 0 deletions
diff --git a/enum.c b/enum.c
index b139b69..f05c556 100644
--- a/enum.c
+++ b/enum.c
@@ -663,6 +663,7 @@ enum_inject(int argc, VALUE *argv, VALUE obj)
}
memo = NEW_MEMO(init, Qnil, op);
rb_block_call(obj, id_each, 0, 0, iter, (VALUE)memo);
+ if (memo->u1.value == Qundef) return Qnil;
return memo->u1.value;
}
diff --git a/test/ruby/test_enum.rb b/test/ruby/test_enum.rb
index 6448796..8bcf929 100644
--- a/test/ruby/test_enum.rb
+++ b/test/ruby/test_enum.rb
@@ -151,6 +151,7 @@ class TestEnumerable < Test::Unit::TestCase
assert_equal(12, @obj.inject(:*))
assert_equal(24, @obj.inject(2) {|z, x| z * x })
assert_equal(24, @obj.inject(2, :*) {|z, x| z * x })
+ assert_equal(nil, @empty.inject() {9})
end
def test_partition