【发布时间】:2011-11-28 04:00:40
【问题描述】:
我有以下代码:
module CarHelper
def call_helpline
puts "Calling helpline..."
end
end
class Car
extend CarHelper
end
class Truck
class << self
include CarHelper
end
end
# Test code
Car.call_helpline
Truck.call_helpline
事实上,两行测试代码都有效。那么有什么区别吗
在我使用“extend”和“include”的方式之间(在单例类中
self)?
【问题讨论】:
标签: ruby singleton metaclass mixins