Tag: subclass

当前的Ruby方法是通过super调用的吗?

在运行时的方法中,有没有办法知道该方法是否已通过子类中的super调用? 例如 module SuperDetector def via_super? # what goes here? end end class Foo include SuperDetector def bar via_super? ? ‘super!’ : ‘nothing special’ end end class Fu “nothing special” Fu.new.bar # => “super!” 我怎么能写via_super? ,或者,如有必要, via_super?(:bar) ?