There is probably a better way, but the general idea is that Object#instance_of? limited only by the current class, not the hierarchy:
module SuperDetector def self.included(clazz) clazz.send(:define_method, :via_super?) do !self.instance_of?(clazz) end end end class Foo include SuperDetector def bar via_super? ? 'super!' : 'nothing special' end end class Fu < Foo def bar super end end Foo.new.bar
However, note that this does not require an explicit
super in the child. If the child does not have such a method and the parent is used,
via_super? will return
true anyway. I don't think there is a way to catch only the
super case, other than checking the stack trace or the code itself.
source share