I'm working on a project where multiple classes will include MyModule
. Upon including the module, I would like the classes that include the module to push a handle to the class type to a specific class-level array.
Psuedocode I've tried below that isn't having the effect I want:
class Poly
@@tracking = []
end
module MyModule
def initialize(klass)
Poly.tracking << self # Where `self` is the class, e.g. `MyClass1`, not an instance of the class.
end
end
class MyClass1
include MyModule
end
class MyClass2
include MyModule
end
When this is loaded, I'd like for Poly.tracking
to equal [MyClass1, MyClass2]
.