Modernize method missing implementations

`...` is both simpler an more correct since the keyword argument
separation.
This commit is contained in:
Jean Boussier 2024-01-16 13:02:12 +01:00
parent 6a9795d4d2
commit 946e46ebcc
29 changed files with 59 additions and 63 deletions

@ -668,7 +668,7 @@ def respond_to?(string, include_all = false)
true
end
def method_missing(*args)
def method_missing(...)
nil
end
end

@ -306,7 +306,7 @@ def any(*args, &block)
end
alias :all :any
def method_missing(name, *args, &block)
def method_missing(name, *, &block)
@variants[name] = block if block_given?
end

@ -326,7 +326,7 @@ def all?; false; end
def to_ary; end
def to_a; end
def method_missing(method, *args)
def method_missing(method, ...)
if method.end_with?("?")
method[0..-2].downcase.to_sym == to_sym
else
@ -373,7 +373,7 @@ def respond_to_missing?(method, _)
method.end_with?("?")
end
def method_missing(method, *args)
def method_missing(method, ...)
false if method.end_with?("?")
end
end

@ -178,9 +178,9 @@ def app_host
end
end
def method_missing(name, *args, &block)
def method_missing(name, ...)
if url_helpers.respond_to?(name)
url_helpers.public_send(name, *args, &block)
url_helpers.public_send(name, ...)
else
super
end

@ -151,8 +151,8 @@ def test_child_session_assertions_bubble_up_to_root
# try to delegate these methods to the session object.
def test_does_not_prevent_method_missing_passing_up_to_ancestors
mixin = Module.new do
def method_missing(name, *args)
name.to_s == "foo" ? "pass" : super
def method_missing(name, ...)
name == :foo ? "pass" : super
end
end
@test.class.superclass.include(mixin)

@ -3895,9 +3895,9 @@ def url_for(options = {})
@app.routes.url_helpers.url_for(options)
end
def method_missing(method, *args, &block)
if method.to_s.match?(/_(path|url)$/)
@app.routes.url_helpers.send(method, *args, &block)
def method_missing(method, ...)
if method.match?(/_(path|url)$/)
@app.routes.url_helpers.send(method, ...)
else
super
end

@ -334,12 +334,12 @@ def respond_to_missing?(*args)
true
end
def method_missing(called, *args, **options, &block)
name = called.to_s.dasherize
def method_missing(called, ...)
name = called.name.dasherize
TagHelper.ensure_valid_html5_tag_name(name)
tag_string(name, *args, **options, &block)
tag_string(name, ...)
end
end

@ -279,8 +279,8 @@ def test_uncountable_route_key
end
private
def method_missing(method, *args)
ActiveModel::Naming.public_send(method, *args)
def method_missing(method, ...)
ActiveModel::Naming.public_send(method, ...)
end
end

@ -18,7 +18,7 @@ def attributes
instance_values.except("address", "friends")
end
def method_missing(method_name, *args)
def method_missing(method_name, ...)
if method_name == :bar
"i_am_bar"
else

@ -16,7 +16,7 @@ class NullPool # :nodoc:
include ConnectionAdapters::AbstractPool
class NullConfig # :nodoc:
def method_missing(*)
def method_missing(...)
nil
end
end

@ -12,12 +12,12 @@ def respond_to_missing?(name, _)
end
end
def method_missing(name, *arguments, &block)
def method_missing(name, ...)
match = Method.match(self, name)
if match && match.valid?
match.define
send(name, *arguments, &block)
send(name, ...)
else
super
end

@ -272,16 +272,16 @@ def load_instances?
use_instantiated_fixtures != :no_instances
end
def method_missing(name, *args, **kwargs, &block)
if fs_name = fixture_sets[name.to_s]
access_fixture(fs_name, *args, **kwargs, &block)
def method_missing(method, ...)
if fs_name = fixture_sets[method.name]
access_fixture(fs_name, ...)
else
super
end
end
def respond_to_missing?(name, include_private = false)
if include_private && fixture_sets.key?(name.to_s)
def respond_to_missing?(method, include_private = false)
if include_private && fixture_sets.key?(method.name)
true
else
super

@ -309,8 +309,8 @@ def is_a?(klass)
model.is_a?(klass)
end
def method_missing(method, *args, &block)
model.send(method, *args, &block)
def method_missing(...)
model.send(...)
end
end

@ -39,7 +39,7 @@ def respond_to_missing?(name, include_private = false)
name.end_with?("?") || super
end
def method_missing(name, *args)
def method_missing(name, ...)
if name.end_with?("?")
any?(name[0..-2])
else

@ -231,15 +231,15 @@ def dispatch(&block)
@broadcasts.each { |logger| block.call(logger) }
end
def method_missing(name, *args, **kwargs, &block)
def method_missing(name, ...)
loggers = @broadcasts.select { |logger| logger.respond_to?(name) }
if loggers.none?
super(name, *args, **kwargs, &block)
super
elsif loggers.one?
loggers.first.send(name, *args, **kwargs, &block)
loggers.first.send(name, ...)
else
loggers.map { |logger| logger.send(name, *args, **kwargs, &block) }
loggers.map { |logger| logger.send(name, ...) }
end
end

@ -183,9 +183,9 @@ def const_missing(name)
target.const_get(name)
end
def method_missing(called, *args, &block)
def method_missing(...)
@deprecator.warn(@message, caller_locations)
target.__send__(called, *args, &block)
target.__send__(...)
end
end
end

@ -506,8 +506,8 @@ def respond_to_missing?(method, _)
value.respond_to?(method)
end
def method_missing(method, *args, &block)
value.public_send(method, *args, &block)
def method_missing(...)
value.public_send(...)
end
def raise_type_error(other)

@ -59,8 +59,8 @@ def initialize(string)
end
# Forward all undefined methods to the wrapped string.
def method_missing(method, *args, &block)
result = @wrapped_string.__send__(method, *args, &block)
def method_missing(method, ...)
result = @wrapped_string.__send__(method, ...)
if method.end_with?("!")
self if result
else

@ -31,8 +31,8 @@ def method_missing(method, *arguments, &block)
end
end
def respond_to_missing?(*arguments)
@context.respond_to?(*arguments)
def respond_to_missing?(...)
@context.respond_to?(...)
end
end
end

@ -46,18 +46,14 @@ def dig(key, *identifiers)
super(key.to_sym, *identifiers)
end
def method_missing(name, *args)
name_string = +name.to_s
if name_string.chomp!("=")
self[name_string] = args.first
else
bangs = name_string.chomp!("!")
if bangs
def method_missing(method, *args)
if method.end_with?("=")
self[method.name.chomp("=")] = args.first
elsif method.end_with?("!")
name_string = method.name.chomp("!")
self[name_string].presence || raise(KeyError.new(":#{name_string} is blank"))
else
self[name_string]
end
self[method.name]
end
end

@ -24,7 +24,7 @@ def respond_to_missing?(method_name, include_private = false)
method_name.end_with?("?") || super
end
def method_missing(method_name, *arguments)
def method_missing(method_name, ...)
if method_name.end_with?("?")
self == method_name[0..-2]
else

@ -235,7 +235,7 @@ def save
def no; false; end
def yes; true; end
def method_missing(sym, *)
def method_missing(sym, ...)
case sym
when /^log_(.*)/
@history << $1

@ -12,7 +12,7 @@ def to_ary
class Proxy
def initialize(target) @target = target end
def method_missing(*a) @target.public_send(*a) end
def method_missing(...) @target.public_send(...) end
end
class DoubtfulToAry

@ -76,7 +76,7 @@ def type
end
module ExtraMissing
def method_missing(sym, *args)
def method_missing(sym, ...)
if sym == :extra_missing
42
else

@ -585,7 +585,7 @@ def method_missing(method, *args)
end
end
def respond_to_missing?(symbol, *)
def respond_to_missing?(symbol, _)
true
end
end

@ -9,9 +9,9 @@ def to_s
"DummyConfig"
end
def method_missing(selector, *args, &blk)
def method_missing(selector, ...)
if @config.respond_to?(selector)
@config.send(selector, *args, &blk)
@config.send(selector, ...)
else
self
end

@ -141,7 +141,7 @@ def apply_rubocop_autocorrect_after_generate!
end
def method_missing(method, *args)
method = method.to_s.delete_suffix("=").to_sym
method = method.name.delete_suffix("=").to_sym
if args.empty?
if method == :rails

@ -15,8 +15,8 @@ def initialize(generator)
%w(template copy_file directory empty_directory inside
empty_directory_with_keep_file create_file chmod shebang).each do |method|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{method}(*args, &block)
@generator.send(:#{method}, *args, &block)
def #{method}(...)
@generator.send(:#{method}, ...)
end
RUBY
end

@ -27,8 +27,8 @@ def configure(&block)
end
private
def method_missing(*args, &block)
instance.send(*args, &block)
def method_missing(...)
instance.send(...)
end
end
end