【发布时间】:2013-03-04 02:23:15
【问题描述】:
我正在尝试使用由该类扩展的类扩展的方法。我正在尝试做的一个例子:
class A
def foo
"Foobar"
end
end
class B
extend A
end
class C
extend B
end
B.foo #=> "Foobar"
C.foo #=> "Foobar"
我不确定这种类型的功能在 Ruby 中是否可用。我知道这可以通过将B 中的extend 更改为include 来实现,但我希望A 中可用的方法可以作为B 和C 中的类方法。
【问题讨论】:
标签: ruby inheritance mixins class-method