ruby-changes:69609
From: Jeremy <ko1@a...>
Date: Sat, 6 Nov 2021 00:22:26 +0900 (JST)
Subject: [ruby-changes:69609] e83c02a768 (master): Delegate keywords from Enumerable#to_a to #each
https://git.ruby-lang.org/ruby.git/commit/?id=e83c02a768 From e83c02a768af61cd0890a75e90bcae1119d8bd93 Mon Sep 17 00:00:00 2001 From: Jeremy Evans <code@j...> Date: Fri, 5 Nov 2021 07:08:21 -0700 Subject: Delegate keywords from Enumerable#to_a to #each Fixes [Bug #18289] --- enum.c | 2 +- test/ruby/test_enum.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/enum.c b/enum.c index d3384f523e9..a51b90296b7 100644 --- a/enum.c +++ b/enum.c @@ -713,7 +713,7 @@ enum_to_a(int argc, VALUE *argv, VALUE obj) https://github.com/ruby/ruby/blob/trunk/enum.c#L713 { VALUE ary = rb_ary_new(); - rb_block_call(obj, id_each, argc, argv, collect_all, ary); + rb_block_call_kw(obj, id_each, argc, argv, collect_all, ary, RB_PASS_CALLED_KEYWORDS); return ary; } diff --git a/test/ruby/test_enum.rb b/test/ruby/test_enum.rb index 702c332cd22..c4706323fde 100644 --- a/test/ruby/test_enum.rb +++ b/test/ruby/test_enum.rb @@ -134,6 +134,11 @@ class TestEnumerable < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_enum.rb#L134 assert_equal([1, 2, 3, 1, 2], @obj.to_a) end + def test_to_a_keywords + def @obj.each(foo:) yield foo end + assert_equal([1], @obj.to_a(foo: 1)) + end + def test_to_a_size_symbol sym = Object.new class << sym -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/