diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 94d4c59d3a..01829d7609 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -625,17 +625,16 @@ def set_payload_for_mail(payload, mail) payload[:perform_deliveries] = mail.perform_deliveries end - def method_missing(method_name, *args) - if action_methods.include?(method_name.to_s) - MessageDelivery.new(self, method_name, *args) + def method_missing(method_name, ...) + if action_methods.include?(method_name.name) + MessageDelivery.new(self, method_name, ...) else super end end - ruby2_keywords(:method_missing) def respond_to_missing?(method, include_all = false) - action_methods.include?(method.to_s) || super + action_methods.include?(method.name) || super end end diff --git a/actionmailer/lib/action_mailer/parameterized.rb b/actionmailer/lib/action_mailer/parameterized.rb index 8d61174739..cbfba5f1de 100644 --- a/actionmailer/lib/action_mailer/parameterized.rb +++ b/actionmailer/lib/action_mailer/parameterized.rb @@ -114,14 +114,13 @@ def initialize(mailer, params) end private - def method_missing(method_name, *args) - if @mailer.action_methods.include?(method_name.to_s) - ActionMailer::Parameterized::MessageDelivery.new(@mailer, method_name, @params, *args) + def method_missing(method_name, ...) + if @mailer.action_methods.include?(method_name.name) + ActionMailer::Parameterized::MessageDelivery.new(@mailer, method_name, @params, ...) else super end end - ruby2_keywords(:method_missing) def respond_to_missing?(method, include_all = false) @mailer.respond_to?(method, include_all) @@ -129,11 +128,10 @@ def respond_to_missing?(method, include_all = false) end class MessageDelivery < ActionMailer::MessageDelivery # :nodoc: - def initialize(mailer_class, action, params, *args) - super(mailer_class, action, *args) + def initialize(mailer_class, action, params, ...) + super(mailer_class, action, ...) @params = params end - ruby2_keywords(:initialize) private def processed_mailer diff --git a/actionpack/lib/abstract_controller/base.rb b/actionpack/lib/abstract_controller/base.rb index 7562faf04e..3d3f03156b 100644 --- a/actionpack/lib/abstract_controller/base.rb +++ b/actionpack/lib/abstract_controller/base.rb @@ -148,7 +148,7 @@ def eager_load! # :nodoc: # # ==== Returns # * self - def process(action, *args) + def process(action, ...) @_action_name = action.to_s unless action_name = _find_action_name(@_action_name) @@ -157,9 +157,8 @@ def process(action, *args) @_response_body = nil - process_action(action_name, *args) + process_action(action_name, ...) end - ruby2_keywords(:process) # Delegates to the class's ::controller_path. def controller_path diff --git a/actionpack/lib/abstract_controller/collector.rb b/actionpack/lib/abstract_controller/collector.rb index 0d1954bc54..b8c156491b 100644 --- a/actionpack/lib/abstract_controller/collector.rb +++ b/actionpack/lib/abstract_controller/collector.rb @@ -7,10 +7,9 @@ module Collector def self.generate_method_for_mime(mime) sym = mime.is_a?(Symbol) ? mime : mime.to_sym class_eval <<-RUBY, __FILE__, __LINE__ + 1 - def #{sym}(*args, &block) - custom(Mime[:#{sym}], *args, &block) + def #{sym}(...) + custom(Mime[:#{sym}], ...) end - ruby2_keywords(:#{sym}) RUBY end @@ -23,7 +22,7 @@ def #{sym}(*args, &block) end private - def method_missing(symbol, *args, &block) + def method_missing(symbol, ...) unless mime_constant = Mime[symbol] raise NoMethodError, "To respond to a custom format, register it as a MIME type first: " \ "https://guides.rubyonrails.org/action_controller_overview.html#restful-downloads. " \ @@ -34,11 +33,10 @@ def method_missing(symbol, *args, &block) if Mime::SET.include?(mime_constant) AbstractController::Collector.generate_method_for_mime(mime_constant) - public_send(symbol, *args, &block) + public_send(symbol, ...) else super end end - ruby2_keywords(:method_missing) end end diff --git a/actionpack/lib/abstract_controller/helpers.rb b/actionpack/lib/abstract_controller/helpers.rb index 043774c500..b6f5291940 100644 --- a/actionpack/lib/abstract_controller/helpers.rb +++ b/actionpack/lib/abstract_controller/helpers.rb @@ -131,10 +131,9 @@ def helper_method(*methods) # controller.send(:'current_user', *args, &block) # end _helpers_for_modification.class_eval <<~ruby_eval.lines.map(&:strip).join(";"), file, line - def #{method}(*args, &block) - controller.send(:'#{method}', *args, &block) + def #{method}(...) + controller.send(:'#{method}', ...) end - ruby2_keywords(:'#{method}') ruby_eval end end diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb index dfa39556ad..e6a9c56263 100644 --- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb +++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb @@ -247,14 +247,13 @@ def assert_routing(path, options, defaults = {}, extras = {}, message = nil) end # ROUTES TODO: These assertions should really work in an integration context - def method_missing(selector, *args, &block) + def method_missing(selector, ...) if defined?(@controller) && @controller && defined?(@routes) && @routes && @routes.named_routes.route_defined?(selector) - @controller.public_send(selector, *args, &block) + @controller.public_send(selector, ...) else super end end - ruby2_keywords(:method_missing) private def create_routes diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index ff3c276ee8..0a2aeb530b 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -431,16 +431,15 @@ def respond_to_missing?(method, _) end # Delegate unhandled messages to the current session instance. - def method_missing(method, *args, &block) + def method_missing(method, ...) if integration_session.respond_to?(method) - integration_session.public_send(method, *args, &block).tap do + integration_session.public_send(method, ...).tap do copy_session_variables! end else super end end - ruby2_keywords(:method_missing) end end diff --git a/actionview/lib/action_view/test_case.rb b/actionview/lib/action_view/test_case.rb index 74f5fd8323..073c5fad02 100644 --- a/actionview/lib/action_view/test_case.rb +++ b/actionview/lib/action_view/test_case.rb @@ -171,10 +171,9 @@ def helper_method(*methods) # Almost a duplicate from ActionController::Helpers methods.flatten.each do |method| _helpers_for_modification.module_eval <<~end_eval, __FILE__, __LINE__ + 1 - def #{method}(*args, &block) # def current_user(*args, &block) - _test_case.send(:'#{method}', *args, &block) # _test_case.send(:'current_user', *args, &block) - end # end - ruby2_keywords(:'#{method}') + def #{method}(...) # def current_user(*args, &block) + _test_case.send(:'#{method}', ...) # _test_case.send(:'current_user', *args, &block) + end # end end_eval end end @@ -416,7 +415,7 @@ def view_assigns end] end - def method_missing(selector, *args) + def method_missing(selector, ...) begin routes = @controller.respond_to?(:_routes) && @controller._routes rescue @@ -426,12 +425,11 @@ def method_missing(selector, *args) if routes && (routes.named_routes.route_defined?(selector) || routes.mounted_helpers.method_defined?(selector)) - @controller.__send__(selector, *args) + @controller.__send__(selector, ...) else super end end - ruby2_keywords(:method_missing) def respond_to_missing?(name, include_private = false) begin diff --git a/activemodel/lib/active_model/attribute_methods.rb b/activemodel/lib/active_model/attribute_methods.rb index 4a76075343..5aad81e137 100644 --- a/activemodel/lib/active_model/attribute_methods.rb +++ b/activemodel/lib/active_model/attribute_methods.rb @@ -66,7 +66,6 @@ module AttributeMethods NAME_COMPILABLE_REGEXP = /\A[a-zA-Z_]\w*[!?=]?\z/ CALL_COMPILABLE_REGEXP = /\A[a-zA-Z_]\w*[!?]?\z/ - FORWARD_PARAMETERS = "*args" included do class_attribute :attribute_aliases, instance_writer: false, default: {} @@ -432,10 +431,8 @@ def define_call(code_generator, name, target_name, mangled_name, parameters, cal "send(#{call_args.join(", ")})" end - modifier = parameters == FORWARD_PARAMETERS ? "ruby2_keywords " : "" - batch << - "#{modifier}def #{mangled_name}(#{parameters || ''})" << + "def #{mangled_name}(#{parameters || ''})" << body << "end" end @@ -449,7 +446,7 @@ class AttributeMethodPattern # :nodoc: def initialize(prefix: "", suffix: "", parameters: nil) @prefix = prefix @suffix = suffix - @parameters = parameters.nil? ? FORWARD_PARAMETERS : parameters + @parameters = parameters.nil? ? "..." : parameters @regex = /\A(?:#{Regexp.escape(@prefix)})(.*)(?:#{Regexp.escape(@suffix)})\z/ @proxy_target = "#{@prefix}attribute#{@suffix}" @method_name = "#{prefix}%s#{suffix}" @@ -477,24 +474,22 @@ def method_name(attr_name) # It's also possible to instantiate related objects, so a Client # class belonging to the +clients+ table with a +master_id+ foreign key # can instantiate master through Client#master. - def method_missing(method, *args, &block) + def method_missing(method, ...) if respond_to_without_attributes?(method, true) super else - match = matched_attribute_method(method.to_s) - match ? attribute_missing(match, *args, &block) : super + match = matched_attribute_method(method.name) + match ? attribute_missing(match, ...) : super end end - ruby2_keywords(:method_missing) # +attribute_missing+ is like +method_missing+, but for attributes. When # +method_missing+ is called we check to see if there is a matching # attribute method. If so, we tell +attribute_missing+ to dispatch the # attribute. This method can be overloaded to customize the behavior. - def attribute_missing(match, *args, &block) - __send__(match.proxy_target, match.attr_name, *args, &block) + def attribute_missing(match, ...) + __send__(match.proxy_target, match.attr_name, ...) end - ruby2_keywords(:attribute_missing) # A +Person+ instance with a +name+ attribute can ask # person.respond_to?(:name), person.respond_to?(:name=), diff --git a/activemodel/lib/active_model/type/registry.rb b/activemodel/lib/active_model/type/registry.rb index e1b256f351..6ce502018d 100644 --- a/activemodel/lib/active_model/type/registry.rb +++ b/activemodel/lib/active_model/type/registry.rb @@ -20,16 +20,15 @@ def register(type_name, klass = nil, &block) registrations[type_name] = block end - def lookup(symbol, *args) + def lookup(symbol, ...) registration = registrations[symbol] if registration - registration.call(symbol, *args) + registration.call(symbol, ...) else raise ArgumentError, "Unknown type #{symbol.inspect}" end end - ruby2_keywords(:lookup) private attr_reader :registrations diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index 36831a1576..e1441a9f99 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -730,10 +730,9 @@ def maintain_test_schema! # :nodoc: end end - def method_missing(name, *args, &block) # :nodoc: - nearest_delegate.send(name, *args, &block) + def method_missing(name, ...) # :nodoc: + nearest_delegate.send(name, ...) end - ruby2_keywords(:method_missing) def migrate(direction) new.migrate direction diff --git a/activerecord/lib/active_record/migration/command_recorder.rb b/activerecord/lib/active_record/migration/command_recorder.rb index 8df167e0e6..bb15bc873a 100644 --- a/activerecord/lib/active_record/migration/command_recorder.rb +++ b/activerecord/lib/active_record/migration/command_recorder.rb @@ -377,14 +377,13 @@ def respond_to_missing?(method, _) end # Forwards any missing method call to the \target. - def method_missing(method, *args, &block) + def method_missing(method, ...) if delegate.respond_to?(method) - delegate.public_send(method, *args, &block) + delegate.public_send(method, ...) else super end end - ruby2_keywords(:method_missing) end end end diff --git a/activerecord/lib/active_record/migration/default_strategy.rb b/activerecord/lib/active_record/migration/default_strategy.rb index a29922d0df..c598564b97 100644 --- a/activerecord/lib/active_record/migration/default_strategy.rb +++ b/activerecord/lib/active_record/migration/default_strategy.rb @@ -6,13 +6,12 @@ class Migration # to the connection adapter. class DefaultStrategy < ExecutionStrategy # :nodoc: private - def method_missing(method, *arguments, &block) - connection.send(method, *arguments, &block) + def method_missing(method, ...) + connection.send(method, ...) end - ruby2_keywords(:method_missing) - def respond_to_missing?(method, *) - connection.respond_to?(method) || super + def respond_to_missing?(method, include_private = false) + connection.respond_to?(method, include_private) || super end def connection diff --git a/activerecord/lib/active_record/relation/delegation.rb b/activerecord/lib/active_record/relation/delegation.rb index 4893e2f3e0..873281a724 100644 --- a/activerecord/lib/active_record/relation/delegation.rb +++ b/activerecord/lib/active_record/relation/delegation.rb @@ -79,10 +79,9 @@ def #{method}(...) end RUBY else - define_method(method) do |*args, &block| - scoping { klass.public_send(method, *args, &block) } + define_method(method) do |*args, **kwargs, &block| + scoping { klass.public_send(method, *args, **kwargs, &block) } end - ruby2_keywords(method) end end end @@ -113,17 +112,16 @@ def name end private - def method_missing(method, *args, &block) + def method_missing(method, ...) if @klass.respond_to?(method) unless Delegation.uncacheable_methods.include?(method) @klass.generate_relation_method(method) end - scoping { @klass.public_send(method, *args, &block) } + scoping { @klass.public_send(method, ...) } else super end end - ruby2_keywords(:method_missing) end module ClassMethods # :nodoc: diff --git a/activesupport/lib/active_support/core_ext/module/delegation.rb b/activesupport/lib/active_support/core_ext/module/delegation.rb index a9f5f20dbd..5de86bb588 100644 --- a/activesupport/lib/active_support/core_ext/module/delegation.rb +++ b/activesupport/lib/active_support/core_ext/module/delegation.rb @@ -336,9 +336,9 @@ def respond_to_missing?(name, include_private = false) #{target}.respond_to?(name) || super end - def method_missing(method, *args, &block) + def method_missing(method, ...) if #{target}.respond_to?(method) - #{target}.public_send(method, *args, &block) + #{target}.public_send(method, ...) else begin super @@ -355,7 +355,6 @@ def method_missing(method, *args, &block) end end end - ruby2_keywords(:method_missing) RUBY end end diff --git a/activesupport/lib/active_support/current_attributes.rb b/activesupport/lib/active_support/current_attributes.rb index 019ccfa9fe..8ff1d326c3 100644 --- a/activesupport/lib/active_support/current_attributes.rb +++ b/activesupport/lib/active_support/current_attributes.rb @@ -177,15 +177,14 @@ def current_instances_key @current_instances_key ||= name.to_sym end - def method_missing(name, *args, &block) + def method_missing(name, ...) # Caches the method definition as a singleton method of the receiver. # # By letting #delegate handle it, we avoid an enclosure that'll capture args. singleton_class.delegate name, to: :instance - send(name, *args, &block) + send(name, ...) end - ruby2_keywords(:method_missing) def respond_to_missing?(name, _) super || instance.respond_to?(name) diff --git a/activesupport/lib/active_support/testing/strict_warnings.rb b/activesupport/lib/active_support/testing/strict_warnings.rb index 52e001d035..4b2098886a 100644 --- a/activesupport/lib/active_support/testing/strict_warnings.rb +++ b/activesupport/lib/active_support/testing/strict_warnings.rb @@ -21,7 +21,7 @@ module RaiseWarnings # :nodoc: %r{/lib/mail/parsers/.*assigned but unused variable - testEof} ) - def warn(message, *) + def warn(message, ...) return if SUPPRESSED_WARNINGS.match?(message) super @@ -32,7 +32,6 @@ def warn(message, *) raise message end - ruby2_keywords :warn if respond_to?(:ruby2_keywords, true) end end diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index d6674eb4dd..46415cd295 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -221,14 +221,13 @@ def respond_to_missing?(name, _) # If the class method does not have a method, then send the method call # to the Railtie instance. - def method_missing(name, *args, &block) + def method_missing(name, ...) if !abstract_railtie? && instance.respond_to?(name) - instance.public_send(name, *args, &block) + instance.public_send(name, ...) else super end end - ruby2_keywords(:method_missing) # receives an instance variable identifier, set the variable value if is # blank and append given block to value, which will be used later in