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