Skip to content

Commit 73b6000

Browse files
committed
Call super from method_added/singleton_method_added methods
If a `method_added`/`singleton_method_added` method on a constant doesn't call `super` then none of the `method_added`/`singleton_method_added` methods on ancestors of the constant ever get called by Ruby. This breaks any code that might want to instrument classes to collect method definition locations, or to do other things when methods are added. In order to be a good citizen, it is best practice to call `super` from these methods.
1 parent b26a9fd commit 73b6000

File tree

3 files changed

+3
-0
lines changed

3 files changed

+3
-0
lines changed

activerecord/lib/active_record/scoping/named.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ def scope(name, body, &block)
190190

191191
private
192192
def singleton_method_added(name)
193+
super
193194
# Most Kernel extends are both singleton and instance methods so
194195
# respond_to is a fast check, but we don't want to define methods
195196
# only on the module (ex. Module#name)

activesupport/lib/active_support/current_attributes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ def respond_to_missing?(name, _)
182182
end
183183

184184
def method_added(name)
185+
super
185186
return if name == :initialize
186187
return unless public_method_defined?(name)
187188
return if respond_to?(name, true)

activesupport/lib/active_support/subscriber.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def detach_from(namespace, notifier = ActiveSupport::Notifications)
6767

6868
# Adds event subscribers for all new methods added to the class.
6969
def method_added(event)
70+
super
7071
# Only public methods are added as subscribers, and only if a notifier
7172
# has been set up. This means that subscribers will only be set up for
7273
# classes that call #attach_to.

0 commit comments

Comments
 (0)