Skip to content

Instantly share code, notes, and snippets.

@IFilonov
Last active January 2, 2022 13:07
Show Gist options
  • Select an option

  • Save IFilonov/e1b5625045959a88a905ad8d5b9720d8 to your computer and use it in GitHub Desktop.

Select an option

Save IFilonov/e1b5625045959a88a905ad8d5b9720d8 to your computer and use it in GitHub Desktop.
anc_desc= {}
ObjectSpace.each_object(Class).select{ |x| x < Object }.each{ |c| anc_desc[c.name] = c.superclass.name if c.name && c.superclass.name }
File.open'result.dot', 'w' do |file|
file.puts %Q(digraph "Ruby#{RUBY_VERSION}" {\n)
file.puts %Q(node [shape=box];\n edge [arrowtail="empty", dir=back];\n)
anc_desc.each.sort_by { |desc, anc| anc + desc }.each{ |desc, anc| file.puts %Q("#{anc}" -> "#{desc}";\n)}
#anc_desc.each{|desc, anc|file.puts%Q("#{anc}" -> "#{desc}";\n)}
file.puts'}';
end
system 'dot -Tsvg result.dot -o ruby.svg'
--before in ubuntu
sudo apt install graphviz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment