Skip to content

Instantly share code, notes, and snippets.

@tlehman
Created November 14, 2014 01:27
Show Gist options
  • Select an option

  • Save tlehman/fea95ccf2da6901a583e to your computer and use it in GitHub Desktop.

Select an option

Save tlehman/fea95ccf2da6901a583e to your computer and use it in GitHub Desktop.
Superclasses and classes
# Starting with a simple String object:
hello = "Hello, World"
def output_class_hierarchy(object)
o = object
while o.class!=Class || (o != nil && o != NilClass)
if o.is_a? Class
puts " #{o} -> #{o.superclass.inspect} [label=superclass,color=red];"
o = o.superclass
else
puts " #{o.inspect} -> #{o.class} [label=class];"
o = o.class
end
end
end
def dot_file_header
puts "digraph {"
end
def dot_file_footer
puts "}"
end
dot_file_header
output_class_hierarchy(hello)
dot_file_footer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment