Skip to content

Commit

Permalink
Fix argument forwarding in Ruby 2.7 (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
qnighy committed Apr 13, 2021
1 parent eb10265 commit 97b2698
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/connection_pool/wrapper.rb
Expand Up @@ -32,12 +32,18 @@ def respond_to?(id, *args)

# rubocop:disable Style/MethodMissingSuper
# rubocop:disable Style/MissingRespondToMissing
if ::RUBY_VERSION >= "2.7.0"
if ::RUBY_VERSION >= "3.0.0"
def method_missing(name, *args, **kwargs, &block)
with do |connection|
connection.send(name, *args, **kwargs, &block)
end
end
elsif ::RUBY_VERSION >= "2.7.0"
ruby2_keywords def method_missing(name, *args, &block)
with do |connection|
connection.send(name, *args, &block)
end
end
else
def method_missing(name, *args, &block)
with do |connection|
Expand Down
7 changes: 7 additions & 0 deletions test/test_connection_pool.rb
Expand Up @@ -14,6 +14,12 @@ def do_something(*_args, increment: 1)
@x
end

def do_something_with_positional_hash(options)
@x += options[:increment] || 1
sleep SLEEP_TIME
@x
end

def fast
@x += 1
end
Expand Down Expand Up @@ -333,6 +339,7 @@ def test_passthru
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)
assert_equal 10, pool.do_something_with_positional_hash({ increment: 2, symbol_key: 3, "string_key" => 4 })
end

def test_passthru_respond_to
Expand Down

0 comments on commit 97b2698

Please sign in to comment.