Skip to content

Instantly share code, notes, and snippets.

@sferik sferik/classes.rb
Created Sep 27, 2009

Embed
What would you like to do?
#!/usr/bin/env ruby
nodes = []
edges = {}
ObjectSpace.each_object(Class) do |klass|
# Skip classes outside the global namespace
next if klass.to_s.include?(':')
# Skip classes like ARGF.class
next if klass.to_s.include?('.')
nodes << klass
edges[klass] = klass.superclass unless klass.superclass.nil?
end
puts 'digraph classes {'
# Add (or remove) DOT formatting options here
puts ' graph [rotate=0, rankdir="RL", overlap=false, splines=true]'
puts ' node [shape="box", style="filled", color="#333333", fillcolor="#396da4", fontcolor="#ffffff", fontname="Helvetica Neue"]'
puts ' edge [arrowhead="open", color="#666666"]'
nodes.sort_by{|c| c.to_s}.each do |c|
puts " #{c}"
end
edges.map.each do |k, v|
puts " #{k} -> #{v}"
end
puts '}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.