tags:

views:

873

answers:

2

How can I list all the types that are declared by a module in Ruby?

+3  A: 

Use the constants method defined in the Module module. From the Ruby documentation:

Module.constants => array

Returns an array of the names of all constants defined in the system. This list includes the names of all modules and classes.

p Module.constants.sort[1..5]

produces:

["ARGV", "ArgumentError", "Array", "Bignum", "Binding"]

You can call constants on any module or class you would like.

p Class.constants
Bruno Gomes
+3  A: 

Not sure if this is what you mean, but you can grab an array of the names of all constants and classes defined in a module by doing

ModuleName.constants

zackola