In Ruby, is there a way to print out all the Global variables and Constants defined / predefined?
views:
29answers:
1
+1
Q:
In Ruby, is there a way to print out all the Global variables and Constants defined / predefined?
+4
A:
The global_variables
method returns an array of all global variable names. To get the names of all the constants defined in a module, send constants
to the relevant module. For example, to get all the constants that you can access without specifying a namespace, use Object.constants
.
Chuck
2010-06-24 05:47:27
To expand on this - you may want to check ObjectSpace module as well.
Eimantas
2010-06-24 06:15:53