summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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