Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize method missing implementations #50766

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion actionmailer/lib/action_mailer/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ def respond_to?(string, include_all = false)
true
end

def method_missing(*args)
def method_missing(...)
nil
end
end
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/metal/mime_responds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions actionpack/lib/action_dispatch/http/mime_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions actionpack/lib/action_dispatch/system_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions actionpack/test/controller/integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions actionpack/test/dispatch/routing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions actionview/lib/action_view/helpers/tag_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions activemodel/test/cases/naming_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion activemodel/test/cases/serialization_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class NullPool # :nodoc:
include ConnectionAdapters::AbstractPool

class NullConfig # :nodoc:
def method_missing(*)
def method_missing(...)
nil
end
end
Expand Down
4 changes: 2 additions & 2 deletions activerecord/lib/active_record/dynamic_matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions activerecord/lib/active_record/test_fixtures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions activerecord/test/cases/relation/where_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion activesupport/lib/active_support/array_inquirer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions activesupport/lib/active_support/broadcast_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions activesupport/lib/active_support/duration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions activesupport/lib/active_support/multibyte/chars.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions activesupport/lib/active_support/option_merger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 7 additions & 11 deletions activesupport/lib/active_support/ordered_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
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

Expand Down
2 changes: 1 addition & 1 deletion activesupport/lib/active_support/string_inquirer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion activesupport/test/callbacks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion activesupport/test/core_ext/array/wrap_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion activesupport/test/core_ext/module_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def type
end

module ExtraMissing
def method_missing(sym, *args)
def method_missing(sym, ...)
if sym == :extra_missing
42
else
Expand Down
2 changes: 1 addition & 1 deletion railties/lib/rails/application/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ def method_missing(method, *args)
end
end

def respond_to_missing?(symbol, *)
def respond_to_missing?(symbol, _)
true
end
end
Expand Down
4 changes: 2 additions & 2 deletions railties/lib/rails/application/dummy_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion railties/lib/rails/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions railties/lib/rails/generators/rails/app/app_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions railties/lib/rails/railtie/configurable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down