Skip to content

Commit

Permalink
Merge pull request #50686 from seanpdoyle/remove-current-attributes-m…
Browse files Browse the repository at this point in the history
…ethod-missing

Avoid definition of methods at runtime in `CurrentAttributes`
  • Loading branch information
byroot committed Jan 10, 2024
2 parents 31a341e + c8e5b0b commit 61b48fe
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions activesupport/lib/active_support/current_attributes.rb
Expand Up @@ -173,16 +173,18 @@ def current_instances_key
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

Expand Down

0 comments on commit 61b48fe

Please sign in to comment.