When you include modules in a class or other module you can call
@mymod.included_modules
to get a list of modules included.
Is there an equivalent for listing the modules a module was extended by?
module Feature1 end module Feature2 extend Feature1 end Feature2.extended_modules #=> [Feature1]
Feature2.singleton_class.included_modules # => [Feature1, ...]
They're there, you just have to look in the right place:
(class << Feature2; self end).included_modules # [Feature1, Kernel]
We can generalize like this:
class Module # Return any modules we +extend+ def extended_modules (class << self; self end).included_modules end end # Now get those extended modules peculiar to Feature2 Feature2.extended_modules - Module.extended_modules # [Feature1]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With