From e9c00d61f426bfcb2e9dfe21f38822d58d2b08ff Mon Sep 17 00:00:00 2001 From: Brian O'Rourke Date: Wed, 3 Mar 2021 14:49:08 -0800 Subject: [PATCH] Ruby 3.0: split positional/keyword args (#143) --- lib/connection_pool/wrapper.rb | 14 +++++++++++--- test/test_connection_pool.rb | 5 +++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/connection_pool/wrapper.rb b/lib/connection_pool/wrapper.rb index 2366b46..249d5eb 100644 --- a/lib/connection_pool/wrapper.rb +++ b/lib/connection_pool/wrapper.rb @@ -32,9 +32,17 @@ class ConnectionPool # rubocop:disable Style/MethodMissingSuper # rubocop:disable Style/MissingRespondToMissing - def method_missing(name, *args, &block) - with do |connection| - connection.send(name, *args, &block) + if ::RUBY_VERSION >= "3.0.0" + def method_missing(name, *args, **kwargs, &block) + with do |connection| + connection.send(name, *args, **kwargs, &block) + end + end + else + def method_missing(name, *args, &block) + with do |connection| + connection.send(name, *args, &block) + end end end # rubocop:enable Style/MethodMissingSuper diff --git a/test/test_connection_pool.rb b/test/test_connection_pool.rb index b7ae9e5..2780bbd 100644 --- a/test/test_connection_pool.rb +++ b/test/test_connection_pool.rb @@ -8,8 +8,8 @@ class TestConnectionPool < Minitest::Test @x = 0 end - def do_something - @x += 1 + def do_something(*_args, increment: 1) + @x += increment sleep SLEEP_TIME @x end @@ -332,6 +332,7 @@ class TestConnectionPool < Minitest::Test assert_equal 2, pool.do_something assert_equal 5, pool.do_something_with_block { 3 } assert_equal 6, pool.with { |net| net.fast } + assert_equal 8, pool.do_something(increment: 2) end def test_passthru_respond_to