[前][次][番号順一覧][スレッド一覧]

ruby-changes:50821

From: nobu <ko1@a...>
Date: Thu, 29 Mar 2018 09:05:53 +0900 (JST)
Subject: [ruby-changes:50821] nobu:r63030 (trunk): array.c: yield blockarg in collect

nobu	2018-03-29 09:05:45 +0900 (Thu, 29 Mar 2018)

  New Revision: 63030

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63030

  Log:
    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]

  Modified files:
    trunk/array.c
    trunk/test/ruby/test_array.rb
Index: array.c
===================================================================
--- array.c	(revision 63029)
+++ array.c	(revision 63030)
@@ -2738,7 +2738,7 @@ rb_ary_collect(VALUE ary) https://github.com/ruby/ruby/blob/trunk/array.c#L2738
     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;
 }
Index: test/ruby/test_array.rb
===================================================================
--- test/ruby/test_array.rb	(revision 63029)
+++ test/ruby/test_array.rb	(revision 63030)
@@ -535,6 +535,8 @@ class TestArray < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_array.rb#L535
     # 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!

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]