Skip to content

Commit

Permalink
Ruby 3.0: split positional/keyword args (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpo committed Mar 3, 2021
1 parent 3eaba66 commit e9c00d6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
14 changes: 11 additions & 3 deletions lib/connection_pool/wrapper.rb
Expand Up @@ -32,9 +32,17 @@ def respond_to?(id, *args)

# 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
Expand Down
5 changes: 3 additions & 2 deletions test/test_connection_pool.rb
Expand Up @@ -8,8 +8,8 @@ def initialize
@x = 0
end

def do_something
@x += 1
def do_something(*_args, increment: 1)
@x += increment
sleep SLEEP_TIME
@x
end
Expand Down Expand Up @@ -332,6 +332,7 @@ def test_passthru
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
Expand Down

0 comments on commit e9c00d6

Please sign in to comment.