From e42f4ae77363e0b85587e67fb86603123bfbd3cb Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 29 Mar 2018 00:05:45 +0000 Subject: array.c: yield blockarg in collect * array.c (rb_ary_collect): yield in block argument semantics always to splat array elements to lambda, for the backward compatibility. [ruby-core:86362] [Bug #14639] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- array.c | 2 +- test/ruby/test_array.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/array.c b/array.c index 1d536284d5..dbcc09d22b 100644 --- a/array.c +++ b/array.c @@ -2738,7 +2738,7 @@ rb_ary_collect(VALUE ary) RETURN_SIZED_ENUMERATOR(ary, 0, 0, ary_enum_length); collect = rb_ary_new2(RARRAY_LEN(ary)); for (i = 0; i < RARRAY_LEN(ary); i++) { - rb_ary_push(collect, rb_yield(RARRAY_AREF(ary, i))); + rb_ary_push(collect, rb_yield_force_blockarg(RARRAY_AREF(ary, i))); } return collect; } diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index 1ff13c7736..6f4999386f 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -535,6 +535,8 @@ class TestArray < Test::Unit::TestCase # Enumerable#collect without block returns an Enumerator. #assert_equal([1, 2, 3], @cls[1, 2, 3].collect) assert_kind_of Enumerator, @cls[1, 2, 3].collect + + assert_equal([[1, 2, 3]], [[1, 2, 3]].collect(&->(a, b, c) {[a, b, c]})) end # also update map! -- cgit v1.2.3