Skip to content

Instantly share code, notes, and snippets.

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

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?
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 do |k, v|
puts " #{k} -> #{v}"
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.