Merge pull request #50686 from seanpdoyle/remove-current-attributes-method-missing

Avoid definition of methods at runtime in `CurrentAttributes`
This commit is contained in:
Jean Boussier 2024-01-10 09:40:09 +01:00 committed by GitHub
commit 61b48fe76d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 7 deletions

View File

@ -173,16 +173,18 @@ module ActiveSupport
end
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, ...)
instance.public_send(name, ...)
end
def respond_to_missing?(name, _)
super || instance.respond_to?(name)
instance.respond_to?(name) || super
end
def method_added(name)
return if name == :initialize
return unless public_method_defined?(name)
return if respond_to?(name, true)
singleton_class.delegate(name, to: :instance, as: self)
end
end