我有一个类Brand
,其中包括一个模块SimpleURLSanitizer
。该模块具有如下定义的类方法:self.included在模块中
class Brand
include SimpleURLSanitizer
end
module SimpleURLSanitizer
def self.included base
base.send :extend, self
end
end
由于我们包含模块,它只能访问模块的实例方法。但是当模块包含在类中时,将调用类方法included
。 base
是Brand
类。这是什么included
方法在做什么?此方法中的self
是指模块还是Brand
类?它是如何工作的?
'included'方法中'self'是指'Brand'类? – mhaseeb
没有指的是模块'SimpleURLSanitizer'。但'base'是指'品牌'类。 – Babar