Skip to content

Instantly share code, notes, and snippets.

@tmikoss
Created November 28, 2012 15:27
Show Gist options
  • Save tmikoss/4161963 to your computer and use it in GitHub Desktop.
Save tmikoss/4161963 to your computer and use it in GitHub Desktop.
List named sub-modules of a module.
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