Fix delegation on Ruby 2.7

* (*args, **kwargs)-delegation does not work on Ruby 2.7.
This commit is contained in:
Benoit Daloze 2020-12-22 12:17:41 +01:00 committed by Marc Siegel
parent ab54c9d47a
commit 7d0f83d13a
1 changed files with 10 additions and 17 deletions

View File

@ -82,25 +82,18 @@ module Docile
# Proxy all methods, excluding {NON_PROXIED_METHODS}, first to `receiver`
# and then to `fallback` if not found.
args_string =
if RUBY_VERSION >= "2.7.0"
"*args, **kwargs, &block"
def method_missing(method, *args, &block)
if @__receiver__.respond_to?(method.to_sym)
@__receiver__.__send__(method.to_sym, *args, &block)
else
"*args, &block"
end
class_eval(<<-METHOD)
def method_missing(method, #{args_string})
if @__receiver__.respond_to?(method.to_sym)
@__receiver__.__send__(method.to_sym, #{args_string})
else
begin
@__fallback__.__send__(method.to_sym, #{args_string})
rescue NoMethodError => e
e.extend(BacktraceFilter)
raise e
end
begin
@__fallback__.__send__(method.to_sym, *args, &block)
rescue NoMethodError => e
e.extend(BacktraceFilter)
raise e
end
end
METHOD
end
ruby2_keywords :method_missing if respond_to?(:ruby2_keywords, true)
end
end