Created
March 10, 2012 01:16
-
-
Save granolocks/2009571 to your computer and use it in GitHub Desktop.
Enumerate Constants in object space
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
class Object | |
def self.sub_constants(prefix = "", namespace=[]) | |
self.constants.each do |constant| | |
constant = constant.to_s | |
puts prefix + constant | |
#puts eval("#{constant}.methods").inspect | |
begin | |
next if %w{ Object Module Class }.include?(constant) || namespace.include?(constant) | |
b = (namespace.dup) << constant | |
eval_string = b.join('::') | |
eval(eval_string).sub_constants(prefix + " ", b) | |
rescue | |
next | |
end | |
end | |
end | |
end | |
Object.sub_constants |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment