Skip to content

Commit 61b48fe

Browse files
authored
Merge pull request rails#50686 from seanpdoyle/remove-current-attributes-method-missing
Avoid definition of methods at runtime in `CurrentAttributes`
2 parents 31a341e + c8e5b0b commit 61b48fe

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

activesupport/lib/active_support/current_attributes.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,18 @@ def current_instances_key
173173
end
174174

175175
def method_missing(name, ...)
176-
# Caches the method definition as a singleton method of the receiver.
177-
#
178-
# By letting #delegate handle it, we avoid an enclosure that'll capture args.
179-
singleton_class.delegate name, to: :instance
180-
181-
send(name, ...)
176+
instance.public_send(name, ...)
182177
end
183178

184179
def respond_to_missing?(name, _)
185-
super || instance.respond_to?(name)
180+
instance.respond_to?(name) || super
181+
end
182+
183+
def method_added(name)
184+
return if name == :initialize
185+
return unless public_method_defined?(name)
186+
return if respond_to?(name, true)
187+
singleton_class.delegate(name, to: :instance, as: self)
186188
end
187189
end
188190

0 commit comments

Comments
 (0)