ruby-changes:58979
From: Jeremy <ko1@a...>
Date: Sat, 30 Nov 2019 15:54:52 +0900 (JST)
Subject: [ruby-changes:58979] 9fa0166a58 (master): [ruby/forwardable] Fix keyword argument separation warnings on Ruby 2.7+
https://git.ruby-lang.org/ruby.git/commit/?id=9fa0166a58 From 9fa0166a580e72adf02562b7d60672c6c362d4b7 Mon Sep 17 00:00:00 2001 From: Jeremy Evans <code@j...> Date: Sat, 7 Sep 2019 12:41:16 -0700 Subject: [ruby/forwardable] Fix keyword argument separation warnings on Ruby 2.7+ Do so in a way that is also compatible with previous versions. https://github.com/ruby/forwardable/commit/b2dd340988 diff --git a/lib/forwardable.rb b/lib/forwardable.rb index 924c605..e8333a3 100644 --- a/lib/forwardable.rb +++ b/lib/forwardable.rb @@ -183,7 +183,9 @@ module Forwardable https://github.com/ruby/ruby/blob/trunk/lib/forwardable.rb#L183 gen = Forwardable._delegator_method(self, accessor, method, ali) # If it's not a class or module, it's an instance - (Module === self ? self : singleton_class).module_eval(&gen) + mod = Module === self ? self : singleton_class + mod.module_eval(&gen) + mod.send(:ruby2_keywords, ali) if RUBY_VERSION >= '2.7' end alias delegate instance_delegate @@ -301,6 +303,7 @@ module SingleForwardable https://github.com/ruby/ruby/blob/trunk/lib/forwardable.rb#L303 gen = Forwardable._delegator_method(self, accessor, method, ali) instance_eval(&gen) + singleton_class.send(:ruby2_keywords, ali) if RUBY_VERSION >= '2.7' end alias delegate single_delegate diff --git a/test/test_forwardable.rb b/test/test_forwardable.rb index 2c0face..dc1408e 100644 --- a/test/test_forwardable.rb +++ b/test/test_forwardable.rb @@ -16,6 +16,10 @@ class TestForwardable < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/test_forwardable.rb#L16 def delegated2 RETURNED2 end + + def delegated1_kw(**kw) + [RETURNED1, kw] + end end def test_def_instance_delegator @@ -38,6 +42,18 @@ class TestForwardable < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/test_forwardable.rb#L42 end end + def test_def_instance_delegator_kw + %i[def_delegator def_instance_delegator].each do |m| + cls = forwardable_class do + __send__ m, :@receiver, :delegated1_kw + end + + ary = cls.new.delegated1_kw b: 1 + assert_same RETURNED1, ary[0] + assert_equal({b: 1}, ary[1]) + end + end + def test_def_instance_delegator_using_args_method_as_receiver %i[def_delegator def_instance_delegator].each do |m| cls = forwardable_class( -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/