Skip to content

Commit ede2236

Browse files
committed
fix: Only apply a method hook to a class that defines the method
1 parent 76aa442 commit ede2236

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/appmap/hook/method.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,12 @@ def activate
125125
hook_method_parameters = hook_method.parameters.dup.freeze
126126
SIGNATURES[[ hook_class, hook_method.name ]] = hook_method_parameters
127127

128-
hook_class.ancestors.first.tap do |cls|
129-
cls.define_method_with_arity(hook_method.name, hook_method.arity, hook_method_def)
128+
hook_class.ancestors.find { |cls| cls.method_defined?(hook_method.name, false) }.tap do |cls|
129+
if cls
130+
cls.define_method_with_arity(hook_method.name, hook_method.arity, hook_method_def)
131+
else
132+
warn "#{hook_method.name} not found on #{hook_class}"
133+
end
130134
end
131135
end
132136

0 commit comments

Comments
 (0)