diff --git a/activesupport/lib/active_support/current_attributes.rb b/activesupport/lib/active_support/current_attributes.rb index fcc73898e65..4ffa1edd5ce 100644 --- a/activesupport/lib/active_support/current_attributes.rb +++ b/activesupport/lib/active_support/current_attributes.rb @@ -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