mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
e02c5f346f
commit
723cee93c4
2 changed files with 2 additions and 0 deletions
1
enum.c
1
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue