我只是在了解Ruby元编程。mixin/modules总是把我弄糊涂。
所以主要的区别只是这个还是有更大的龙潜伏着? 例如< / p >
module ReusableModule
def module_method
puts "Module Method: Hi there!"
end
end
class ClassThatIncludes
include ReusableModule
end
class ClassThatExtends
extend ReusableModule
end
puts "Include"
ClassThatIncludes.new.module_method # "Module Method: Hi there!"
puts "Extend"
ClassThatExtends.module_method # "Module Method: Hi there!"