Created
November 28, 2012 15:27
-
-
Save tmikoss/4161963 to your computer and use it in GitHub Desktop.
List named sub-modules of a module.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module NamedSubmodules | |
def named_submodules | |
constants.map{ |c| const_get c }.select{ |c| c.is_a?(Module) && c.const_defined?('SUBMODULE_NAME') } | |
end | |
def named_submodule_list | |
named_submodules.inject({}) do |hash, mod| | |
hash[mod.to_s] = mod.const_get('SUBMODULE_NAME') | |
hash | |
end | |
end | |
end | |
Module.send :include, NamedSubmodules |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment