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

View File

@ -668,7 +668,7 @@ module ActionMailer
true
end
def method_missing(*args)
def method_missing(...)
nil
end
end

View File

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

View File

@ -326,7 +326,7 @@ module Mime
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 @@ module Mime
method.end_with?("?")
end
def method_missing(method, *args)
def method_missing(method, ...)
false if method.end_with?("?")
end
end

View File

@ -178,9 +178,9 @@ module ActionDispatch
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

View File

@ -151,8 +151,8 @@ class IntegrationTestTest < ActiveSupport::TestCase
# 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)

View File

@ -3895,9 +3895,9 @@ private
@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

View File

@ -334,12 +334,12 @@ module ActionView
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

View File

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

View File

@ -18,7 +18,7 @@ class SerializationTest < ActiveModel::TestCase
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

View File

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

View File

@ -12,12 +12,12 @@ module ActiveRecord
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

View File

@ -272,16 +272,16 @@ module ActiveRecord
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

View File

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

View File

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

View File

@ -231,15 +231,15 @@ module ActiveSupport
@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

View File

@ -183,9 +183,9 @@ module ActiveSupport
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

View File

@ -506,8 +506,8 @@ module ActiveSupport
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)

View File

@ -59,8 +59,8 @@ module ActiveSupport # :nodoc:
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

View File

@ -31,8 +31,8 @@ module ActiveSupport
end
end
def respond_to_missing?(*arguments)
@context.respond_to?(*arguments)
def respond_to_missing?(...)
@context.respond_to?(...)
end
end
end

View File

@ -46,18 +46,14 @@ module ActiveSupport
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
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
bangs = name_string.chomp!("!")
if bangs
self[name_string].presence || raise(KeyError.new(":#{name_string} is blank"))
else
self[name_string]
end
self[method.name]
end
end

View File

@ -24,7 +24,7 @@ module ActiveSupport
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

View File

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

View File

@ -12,7 +12,7 @@ class WrapTest < ActiveSupport::TestCase
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

View File

@ -76,7 +76,7 @@ Product = Struct.new(:name) do
end
module ExtraMissing
def method_missing(sym, *args)
def method_missing(sym, ...)
if sym == :extra_missing
42
else

View File

@ -585,7 +585,7 @@ module Rails
end
end
def respond_to_missing?(symbol, *)
def respond_to_missing?(symbol, _)
true
end
end

View File

@ -9,9 +9,9 @@ class DummyConfig # :nodoc:
"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

View File

@ -141,7 +141,7 @@ module Rails
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

View File

@ -15,8 +15,8 @@ module Rails
%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

View File

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