diff --git a/lib/forwardable.rb b/lib/forwardable.rb index 924c605c6e..e8333a359e 100644 --- a/lib/forwardable.rb +++ b/lib/forwardable.rb @@ -183,7 +183,9 @@ module Forwardable 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 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 2c0face3ba..dc1408e8ed 100644 --- a/test/test_forwardable.rb +++ b/test/test_forwardable.rb @@ -16,6 +16,10 @@ class TestForwardable < Test::Unit::TestCase 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 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(