I have a class that has a number of modules that are mixed in with it based on some runtime criteria.
I want to be able to get a list of which modules have been mixed into this class. How can you do that?
UPDATE
So when I said class I meant object as it is the object that is being extended at runtime using:
obj.extend(MyModule)
obj.included_modules and obj.ancestors don’t exist so you can’t get the modules that have been mixed in from there.
Try:
for example:
UPDATE
To get the modules mixed into an object instance at runtime you’ll need to retrieve the eigenclass of the instance. There is no clean way to do this in Ruby, but a reasonably common idiom is the following:
If you find yourself using this a lot, you can make it generally available:
and the solution is then: