Last active
December 25, 2016 07:15
-
-
Save markburns/9c4ac9495ee56a77de16983d6e83d49e to your computer and use it in GitHub Desktop.
If you ever use class instance variables, you'll run into state hell. This recursively searches a namespace for any instance variables and prints them out. Skipping circular constant definitions
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 show_class_instance_variables(n) | |
puts "#{n} #{n.instance_variables}" if n.instance_variables.length.positive? | |
return unless (n.is_a?(Class) || n.is_a?(Module)) | |
n.constants.each do |c| | |
next if n==c | |
klass = n.const_get(c) | |
if klass.is_a?(Class) || klass.is_a?(Module) | |
puts "#{klass} #{klass.instance_variables}" if klass.instance_variables.length.positive? | |
klass.constants.each do |s| | |
s = klass.const_get(s) | |
next if s == klass || s == n | |
show_class_instance_variables(s) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment