I have a mixin for which I would like to get a list of all the classes that have included it. In the mixin module, I did the following:
module MyModule
def
Actually, your module extension module works. The problem is in your test: when you created a random unnamed class with Class.new, you forgot to include MyModule. As a side note, you can take your read-only accessor for classes that include the module and use the helpful Module#attr_reader method.
You probably should use extend instead of include since former adds class level methods, while latter - instance level methods (why you have access to @classes).
Try this:
module MyModule
extend ListIncludedClasses::ClassMethods
end
module MyMod; end
class A; include MyMod; end
class B < A; end
class C; end
ObjectSpace.each_object(Class).select { |c| c.included_modules.include? MyMod }
#=> [B, A]