I'm looking at a module X which contains two modules called "InstanceMethods
" and "ClassMethods
".
The last definition in module X is this:
def self.included(base)
base.send :include, InstanceMethods
base.send :extend, ClassMethods
end
What does this do?
included
gets called whenever a module is included into another module or class. In this case it will try to invoke base
's include
method to get the module methods, variables and constants from InstanceMethods
added into base
and then will try to invoke base
's extend
method to get the instance methods from ClassMethods
added to base
.
It could also have been
def self.included( base )
base.include( InstanceMethods )
base.extend( ClassMethods )
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With