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
1
enum.c
1
enum.c
@ -663,6 +663,7 @@ enum_inject(int argc, VALUE *argv, VALUE obj)
|
|||||||
}
|
}
|
||||||
memo = NEW_MEMO(init, Qnil, op);
|
memo = NEW_MEMO(init, Qnil, op);
|
||||||
rb_block_call(obj, id_each, 0, 0, iter, (VALUE)memo);
|
rb_block_call(obj, id_each, 0, 0, iter, (VALUE)memo);
|
||||||
|
if (memo->u1.value == Qundef) return Qnil;
|
||||||
return memo->u1.value;
|
return memo->u1.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,6 +151,7 @@ class TestEnumerable < Test::Unit::TestCase
|
|||||||
assert_equal(12, @obj.inject(:*))
|
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(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
|
end
|
||||||
|
|
||||||
def test_partition
|
def test_partition
|
||||||
|
Loading…
x
Reference in New Issue
Block a user