blog.absurd:li - press play on tape
February 17th 2010
Tagged ruby, internals, graphviz, humor

The Ruby Object Hierarchy

Every self respecting ruby programmer has one of these on his blog. Join the club.

(Click for a pdf of this. Filled triangles are class relationships, empty triangles are super relationships, funky diamonds are funky metaclass relationships, thanks _why!)

Here is the source code for this. A few notes on the code:

The code also graphs the ‘actual class’ as reported here. I didn’t see the use of that, so it’s gone from the version displayed here.

This is probably the most shoddy piece of code I’ve ever released. Note to self: Breathe out, relax. It doesn’t actually hurt.

If you want to run this yourself, call it like this:

  $ ruby extconf.rb && make
  (... snippage ...)
  $ ruby graph.rb RECURSION_DEPTH >

The code does depth first graph traversal over Ruby’s object graph and outputs a graphviz dot file. It seems that while recursion depths bigger than 3 are sure funky, they don’t add much to the picture.

A few things that are interesting in the above graph (trying not to be redundant with others):

  • There are really a lot more metaclasses than you think. They might gather in groups and descend upon you in your sleep, even. You think turtles is bad? Metaclasses is way badder.
  • Class really ties the room together. Without it, Ruby would really be off balance. I guess that’s why its called class oriented programming.
  • Everything is created out of nothing. It fits with my belief system to have nil sit on the top of that diagram.

Happy hacking!