Module Inclusion
A very common occurrence - especially when writing a Module
for a library - is knowing when that module has been included or mixed-into another Class
or Module
using Module#include
.
Ruby provides the Module.included
method to receive callbacks when this happens. Module.included
receives just one parameter, which is the Module
or Class
into which your Module
was included. Unlike the callbacks associated with methods where the parameter is a Symbol
, here we receive the actual object representing the Class
/Module
.
As always, lifecycle callbacks are easiest to teach through exercises, so here is one for you now.