Created
September 27, 2012 14:07
-
-
Save rbuck/3794199 to your computer and use it in GitHub Desktop.
How to get a hash listing all Ruby globals
This file contains 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
def get_globals | |
hash = {} | |
global_variables.sort.map do |symbol| | |
begin | |
value = eval ("#{symbol}") | |
hash[symbol] = value unless value.nil? | |
rescue | |
nil | |
end | |
end | |
hash | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment