By "kids" you seem to mean modules nested in this module, right? Nothing to do with inheritance relationships?
Assuming that you mean only nested modules, the following should work:
class Module
def children
constants.collect { |c| const_get(c) }.
select { |m| m.instance_of?(Module) }
end
end
EDIT: You may need to use constants(false)it to prevent the modules from constantly searching further down the inheritance chain.
source
share