【发布时间】:2011-11-12 17:02:55
【问题描述】:
扩展时调用的东西。
例如。这段代码:
module M
def init(x)
@x = 5
self
end
def foo
super
puts @x
end
end
class D
def foo
puts 1
end
end
D.new.extend(M).init(5).foo
有效并返回 1 5。但我想将最后一行更改为阅读
D.new.extend(M.init(5)).foo
或者更好
D.new.extend(M(5)).foo
防止错误没有设置@x。
在类似的情况下,我可以说类似
class X
include Debug(5)
【问题讨论】:
标签: ruby constructor module mixins