Skip to content

Commit ef65e5f

Browse files
committed
Cleanup usage of ruby2_keywords
Now that we no longer support Ruby 2.7, many `ruby2_keyword` calls can be eliminated. The ones that are left could be eliminated but would end up substantially slower or more compliacated so I left them for now.
1 parent 1702b6c commit ef65e5f

File tree

18 files changed

+54
-80
lines changed

18 files changed

+54
-80
lines changed

actionmailer/lib/action_mailer/base.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -625,17 +625,16 @@ def set_payload_for_mail(payload, mail)
625625
payload[:perform_deliveries] = mail.perform_deliveries
626626
end
627627

628-
def method_missing(method_name, *args)
629-
if action_methods.include?(method_name.to_s)
630-
MessageDelivery.new(self, method_name, *args)
628+
def method_missing(method_name, ...)
629+
if action_methods.include?(method_name.name)
630+
MessageDelivery.new(self, method_name, ...)
631631
else
632632
super
633633
end
634634
end
635-
ruby2_keywords(:method_missing)
636635

637636
def respond_to_missing?(method, include_all = false)
638-
action_methods.include?(method.to_s) || super
637+
action_methods.include?(method.name) || super
639638
end
640639
end
641640

actionmailer/lib/action_mailer/parameterized.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,26 +114,24 @@ def initialize(mailer, params)
114114
end
115115

116116
private
117-
def method_missing(method_name, *args)
118-
if @mailer.action_methods.include?(method_name.to_s)
119-
ActionMailer::Parameterized::MessageDelivery.new(@mailer, method_name, @params, *args)
117+
def method_missing(method_name, ...)
118+
if @mailer.action_methods.include?(method_name.name)
119+
ActionMailer::Parameterized::MessageDelivery.new(@mailer, method_name, @params, ...)
120120
else
121121
super
122122
end
123123
end
124-
ruby2_keywords(:method_missing)
125124

126125
def respond_to_missing?(method, include_all = false)
127126
@mailer.respond_to?(method, include_all)
128127
end
129128
end
130129

131130
class MessageDelivery < ActionMailer::MessageDelivery # :nodoc:
132-
def initialize(mailer_class, action, params, *args)
133-
super(mailer_class, action, *args)
131+
def initialize(mailer_class, action, params, ...)
132+
super(mailer_class, action, ...)
134133
@params = params
135134
end
136-
ruby2_keywords(:initialize)
137135

138136
private
139137
def processed_mailer

actionpack/lib/abstract_controller/base.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def eager_load! # :nodoc:
148148
#
149149
# ==== Returns
150150
# * <tt>self</tt>
151-
def process(action, *args)
151+
def process(action, ...)
152152
@_action_name = action.to_s
153153

154154
unless action_name = _find_action_name(@_action_name)
@@ -157,9 +157,8 @@ def process(action, *args)
157157

158158
@_response_body = nil
159159

160-
process_action(action_name, *args)
160+
process_action(action_name, ...)
161161
end
162-
ruby2_keywords(:process)
163162

164163
# Delegates to the class's ::controller_path.
165164
def controller_path

actionpack/lib/abstract_controller/collector.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ module Collector
77
def self.generate_method_for_mime(mime)
88
sym = mime.is_a?(Symbol) ? mime : mime.to_sym
99
class_eval <<-RUBY, __FILE__, __LINE__ + 1
10-
def #{sym}(*args, &block)
11-
custom(Mime[:#{sym}], *args, &block)
10+
def #{sym}(...)
11+
custom(Mime[:#{sym}], ...)
1212
end
13-
ruby2_keywords(:#{sym})
1413
RUBY
1514
end
1615

@@ -23,7 +22,7 @@ def #{sym}(*args, &block)
2322
end
2423

2524
private
26-
def method_missing(symbol, *args, &block)
25+
def method_missing(symbol, ...)
2726
unless mime_constant = Mime[symbol]
2827
raise NoMethodError, "To respond to a custom format, register it as a MIME type first: " \
2928
"https://guides.rubyonrails.org/action_controller_overview.html#restful-downloads. " \
@@ -34,11 +33,10 @@ def method_missing(symbol, *args, &block)
3433

3534
if Mime::SET.include?(mime_constant)
3635
AbstractController::Collector.generate_method_for_mime(mime_constant)
37-
public_send(symbol, *args, &block)
36+
public_send(symbol, ...)
3837
else
3938
super
4039
end
4140
end
42-
ruby2_keywords(:method_missing)
4341
end
4442
end

actionpack/lib/abstract_controller/helpers.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,9 @@ def helper_method(*methods)
131131
# controller.send(:'current_user', *args, &block)
132132
# end
133133
_helpers_for_modification.class_eval <<~ruby_eval.lines.map(&:strip).join(";"), file, line
134-
def #{method}(*args, &block)
135-
controller.send(:'#{method}', *args, &block)
134+
def #{method}(...)
135+
controller.send(:'#{method}', ...)
136136
end
137-
ruby2_keywords(:'#{method}')
138137
ruby_eval
139138
end
140139
end

actionpack/lib/action_dispatch/testing/assertions/routing.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,13 @@ def assert_routing(path, options, defaults = {}, extras = {}, message = nil)
247247
end
248248

249249
# ROUTES TODO: These assertions should really work in an integration context
250-
def method_missing(selector, *args, &block)
250+
def method_missing(selector, ...)
251251
if defined?(@controller) && @controller && defined?(@routes) && @routes && @routes.named_routes.route_defined?(selector)
252-
@controller.public_send(selector, *args, &block)
252+
@controller.public_send(selector, ...)
253253
else
254254
super
255255
end
256256
end
257-
ruby2_keywords(:method_missing)
258257

259258
private
260259
def create_routes

actionpack/lib/action_dispatch/testing/integration.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,16 +431,15 @@ def respond_to_missing?(method, _)
431431
end
432432

433433
# Delegate unhandled messages to the current session instance.
434-
def method_missing(method, *args, &block)
434+
def method_missing(method, ...)
435435
if integration_session.respond_to?(method)
436-
integration_session.public_send(method, *args, &block).tap do
436+
integration_session.public_send(method, ...).tap do
437437
copy_session_variables!
438438
end
439439
else
440440
super
441441
end
442442
end
443-
ruby2_keywords(:method_missing)
444443
end
445444
end
446445

actionview/lib/action_view/test_case.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,9 @@ def helper_method(*methods)
171171
# Almost a duplicate from ActionController::Helpers
172172
methods.flatten.each do |method|
173173
_helpers_for_modification.module_eval <<~end_eval, __FILE__, __LINE__ + 1
174-
def #{method}(*args, &block) # def current_user(*args, &block)
175-
_test_case.send(:'#{method}', *args, &block) # _test_case.send(:'current_user', *args, &block)
176-
end # end
177-
ruby2_keywords(:'#{method}')
174+
def #{method}(...) # def current_user(*args, &block)
175+
_test_case.send(:'#{method}', ...) # _test_case.send(:'current_user', *args, &block)
176+
end # end
178177
end_eval
179178
end
180179
end
@@ -416,7 +415,7 @@ def view_assigns
416415
end]
417416
end
418417

419-
def method_missing(selector, *args)
418+
def method_missing(selector, ...)
420419
begin
421420
routes = @controller.respond_to?(:_routes) && @controller._routes
422421
rescue
@@ -426,12 +425,11 @@ def method_missing(selector, *args)
426425
if routes &&
427426
(routes.named_routes.route_defined?(selector) ||
428427
routes.mounted_helpers.method_defined?(selector))
429-
@controller.__send__(selector, *args)
428+
@controller.__send__(selector, ...)
430429
else
431430
super
432431
end
433432
end
434-
ruby2_keywords(:method_missing)
435433

436434
def respond_to_missing?(name, include_private = false)
437435
begin

activemodel/lib/active_model/attribute_methods.rb

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ module AttributeMethods
6666

6767
NAME_COMPILABLE_REGEXP = /\A[a-zA-Z_]\w*[!?=]?\z/
6868
CALL_COMPILABLE_REGEXP = /\A[a-zA-Z_]\w*[!?]?\z/
69-
FORWARD_PARAMETERS = "*args"
7069

7170
included do
7271
class_attribute :attribute_aliases, instance_writer: false, default: {}
@@ -432,10 +431,8 @@ def define_call(code_generator, name, target_name, mangled_name, parameters, cal
432431
"send(#{call_args.join(", ")})"
433432
end
434433

435-
modifier = parameters == FORWARD_PARAMETERS ? "ruby2_keywords " : ""
436-
437434
batch <<
438-
"#{modifier}def #{mangled_name}(#{parameters || ''})" <<
435+
"def #{mangled_name}(#{parameters || ''})" <<
439436
body <<
440437
"end"
441438
end
@@ -449,7 +446,7 @@ class AttributeMethodPattern # :nodoc:
449446
def initialize(prefix: "", suffix: "", parameters: nil)
450447
@prefix = prefix
451448
@suffix = suffix
452-
@parameters = parameters.nil? ? FORWARD_PARAMETERS : parameters
449+
@parameters = parameters.nil? ? "..." : parameters
453450
@regex = /\A(?:#{Regexp.escape(@prefix)})(.*)(?:#{Regexp.escape(@suffix)})\z/
454451
@proxy_target = "#{@prefix}attribute#{@suffix}"
455452
@method_name = "#{prefix}%s#{suffix}"
@@ -477,24 +474,22 @@ def method_name(attr_name)
477474
# It's also possible to instantiate related objects, so a <tt>Client</tt>
478475
# class belonging to the +clients+ table with a +master_id+ foreign key
479476
# can instantiate master through <tt>Client#master</tt>.
480-
def method_missing(method, *args, &block)
477+
def method_missing(method, ...)
481478
if respond_to_without_attributes?(method, true)
482479
super
483480
else
484-
match = matched_attribute_method(method.to_s)
485-
match ? attribute_missing(match, *args, &block) : super
481+
match = matched_attribute_method(method.name)
482+
match ? attribute_missing(match, ...) : super
486483
end
487484
end
488-
ruby2_keywords(:method_missing)
489485

490486
# +attribute_missing+ is like +method_missing+, but for attributes. When
491487
# +method_missing+ is called we check to see if there is a matching
492488
# attribute method. If so, we tell +attribute_missing+ to dispatch the
493489
# attribute. This method can be overloaded to customize the behavior.
494-
def attribute_missing(match, *args, &block)
495-
__send__(match.proxy_target, match.attr_name, *args, &block)
490+
def attribute_missing(match, ...)
491+
__send__(match.proxy_target, match.attr_name, ...)
496492
end
497-
ruby2_keywords(:attribute_missing)
498493

499494
# A +Person+ instance with a +name+ attribute can ask
500495
# <tt>person.respond_to?(:name)</tt>, <tt>person.respond_to?(:name=)</tt>,

activemodel/lib/active_model/type/registry.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,15 @@ def register(type_name, klass = nil, &block)
2020
registrations[type_name] = block
2121
end
2222

23-
def lookup(symbol, *args)
23+
def lookup(symbol, ...)
2424
registration = registrations[symbol]
2525

2626
if registration
27-
registration.call(symbol, *args)
27+
registration.call(symbol, ...)
2828
else
2929
raise ArgumentError, "Unknown type #{symbol.inspect}"
3030
end
3131
end
32-
ruby2_keywords(:lookup)
3332

3433
private
3534
attr_reader :registrations

0 commit comments

Comments
 (0)