Created
November 14, 2014 01:27
-
-
Save tlehman/fea95ccf2da6901a583e to your computer and use it in GitHub Desktop.
Superclasses and classes
This file contains hidden or 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
| # 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