I do not think the modules track what included them. But they work MyModule.included(SomeClass)like a callback when they turn on, so you can track yourself.
module IncludedModule
@@included_classes = []
def self.included(base)
@@included_classes << base
end
def self.included_classes
@@included_classes
end
end
class IncludingClass
include IncludedModule
end
puts IncludedModule.included_classes
There is probably a way to scan all the declared classes and ask them what they turned on through SomeClass.included_modules, but this kind of hairy, and will be much slower.
source
share