Handle kwargs only in Ruby >= '2.7'

To avoid "ArgumentError: wrong number of arguments" in old rubies
This commit is contained in:
Akira Matsuda 2019-09-08 09:06:42 +09:00
parent 72c1aa21c1
commit de3d9680ac

@ -360,13 +360,14 @@ def attribute_method_matchers_matching(method_name)
# using the given `extra` args. This falls back on `define_method`
# and `send` if the given names cannot be compiled.
def define_proxy_call(include_private, mod, name, target, *extra)
kw = RUBY_VERSION >= '2.7' ? ", **options" : nil
defn = if NAME_COMPILABLE_REGEXP.match?(name)
"def #{name}(*args)"
"def #{name}(*args#{kw})"
else
"define_method(:'#{name}') do |*args|"
"define_method(:'#{name}') do |*args#{kw}|"
end
extra = (extra.map!(&:inspect) << "*args").join(", ")
extra = (extra.map!(&:inspect) << "*args#{kw}").join(", ")
body = if CALL_COMPILABLE_REGEXP.match?(target)
"#{"self." unless include_private}#{target}(#{extra})"