Skip to content

Commit a7752a1

Browse files
Edouard-chingeorge-ma
authored andcommitted
Remove method_added hook doing nothing:
- ### Context In rails#54646, I fixed a bug. The patch introduced a behaviour change which was caught by sorbet typechecking. ------------------------ ```ruby class Current < ActiveSupport::Current def foo end end ``` Previously: ```ruby Current.method(:foo).source_location => nil ``` After: ```ruby Current.method(:foo).source_location => [lib/active_support/current_attributes.rb", 191] ``` -------------------- Basically, before, we were never creating a delegation method to the class, and instead relied on `method_missing` entirely. ### Problem There is no problem per se, but this method_added hook used to do nothing. And the previous patch now creates a delegation on the class. This is because when a method is added, `respond_to?` on the instance will always return `true` since we have just defined it. When calling `attribute :foo`, a method on the **singleton class** gets created, but doesn't not trigger our method_added hook defined on the **class**.
1 parent b0df48c commit a7752a1

File tree

1 file changed

+0
-8
lines changed

1 file changed

+0
-8
lines changed

activesupport/lib/active_support/current_attributes.rb

-8
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,6 @@ def method_missing(name, ...)
182182
def respond_to_missing?(name, _)
183183
instance.respond_to?(name) || super
184184
end
185-
186-
def method_added(name)
187-
super
188-
return if name == :initialize
189-
return unless public_method_defined?(name)
190-
return if singleton_class.method_defined?(name) || singleton_class.private_method_defined?(name)
191-
Delegation.generate(singleton_class, [name], to: :instance, as: self, nilable: false)
192-
end
193185
end
194186

195187
class_attribute :defaults, instance_writer: false, default: {}.freeze

0 commit comments

Comments
 (0)