In the same way that the class could include some singleton methods,the Module could include some singleton methods,too.But if we implement a class which include a Module which contians some singleton methods,does these methods become to the class's singleton methods?The answer is 'no'.There is a hook called append_features that we can override.It's called with a parameter that is the destination class or module.For an example of its use,see the following codes:
Note:
you should call the "super" when you override the append_features method.
It's very interesting.
These code copy from the <ruby way=""> book.</ruby>
ruby 代码
- module MyMod
- def MyMod.append_features(someClass)
- def someClass.modmeth
- puts "Module (class) method"
- end
- super
- end
- end
- class AppendFeatures
- include MyMod
- def initialize
- end
- end
- AppendFeatures.modmeth
Note:
you should call the "super" when you override the append_features method.
It's very interesting.
These code copy from the <ruby way=""> book.</ruby>