You can trace until you find the end of the class definition. I did this in a method that I called after_inherited:
class Class
def after_inherited child = nil, &blk
line_class = nil
set_trace_func(lambda do |event, file, line, id, binding, classname|
unless line_class
line_class = line if event == 'class'
else
if line == line_class && event == 'end'
set_trace_func nil
blk.call child
end
end
end)
end
end
class A
def self.inherited(child)
after_inherited do
puts "XXX"
end
end
end
class B < A
puts "YYY"
end
Conclusion:
YYY
XXX
source
share