举个例子 以下是个父类
class Base
  attr_accessor :flag
  def exec; raise NotImplementedError; end
  def print_flag; print("#{self.class} - #{flag}"); end
end
这时有个子类BizA继承了Base,并实现了exec
class BizA < Base
  def exec; self.flag = true; self; end
end
现在如果执行BizA.new.exec.print_flag,会输出BizA - true
上面是前提
我的问题是,如果有领个子类BIzB,能否在BizB继承Base的情况下,拥有和 BizA 相同实现的exec方法
class BizB < Base
  # 不去实现exec,而是复制BizA的exec到当前class
end
然后在执行BizB.new.exec.print_flag时,输出BizB - true
我知道的几种方式在这里列一下,但不是我想要的效果
BizB.new.exec.print_flag时,必须要提供一个 BizA 的实例,而 exec 内部获取 self 时获取到的也是 BizA 的实例,会出现问题Base的基类,给用户继承使用,Base中还有很多其他的方法和属性,所以不考虑