I see this pattern a lot:
module Article::Score
def self.included(base)
base.send :extend, ClassMethods
base.send :include, InstanceMethods
end
module ClassMethods
...
end
module InstanceMethods
...
end
end
Then in the article model, I see this
class Article
include Article::Score
...
end
so my guess is that "base" probably refers to the article class and we're just including the instance methods and extending the class methods. But can someone explain the snippet "self.included(base)" and give an overview of what's going on there?
The self.included function is called when the module is included. It allows methods to be executed in the context of the base (where the module is included).
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