我正在玩include,extend今天发现了一些我不太明白的东西。
module Dragon
def roar
'roar'
end
end
module Knight
include Dragon
def fight
'fight'
end
end
class Other
extend Knight
end
puts Other.roar # -> 'roar'
为什么它roar可以作为类方法使用Other?我做了extend Knight这使得Knight's方法可以作为类方法使用。Knight反过来会include Dragon,但这应该使Dragon方法可以作为instance方法使用。但这不是这里发生的唯一奇怪的事情,你也不能创建模块的实例,那为什么我可以include在一个模块上呢?