ruby-changes:35846
From: nobu <ko1@a...>
Date: Wed, 15 Oct 2014 15:27:40 +0900 (JST)
Subject: [ruby-changes:35846] nobu:r47928 (trunk): enum.c: nil if no iteration
nobu 2014-10-15 15:27:30 +0900 (Wed, 15 Oct 2014) New Revision: 47928 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47928 Log: enum.c: nil if no iteration * enum.c (enum_inject): return nil if no iteration, instead of Qundef. Modified files: trunk/enum.c trunk/test/ruby/test_enum.rb Index: enum.c =================================================================== --- enum.c (revision 47927) +++ enum.c (revision 47928) @@ -663,6 +663,7 @@ enum_inject(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/enum.c#L663 } 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; } Index: test/ruby/test_enum.rb =================================================================== --- test/ruby/test_enum.rb (revision 47927) +++ test/ruby/test_enum.rb (revision 47928) @@ -151,6 +151,7 @@ class TestEnumerable < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_enum.rb#L151 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/