This is what I’ve got, but it also finds classes and other constants.. is there a better way?
class Module
def children
constants.collect { |c| const_get(c) }.compact
end
end
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
By ‘children’ you seem to mean modules nested under a given module, right? Nothing to do with inheritance relationships?
Assuming you just mean nested modules, the following should work:
EDIT: You may need to use
constants(false)to prevent constant look-up on modules further up the inheritance chain.