# Studying the object model

**URL:** <https://www.ruby-forum.com/t/studying-the-object-model/158874>\
**Category:** Ruby\
**Created:** [January 28, 2009, 11:46pm UTC](https://www.ruby-forum.com/t/studying-the-object-model/158874 "2009-01-28T23:46:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/85f322/32.png) [@alby](https://www.ruby-forum.com/u/alby)\
**Post date:** [January 28, 2009, 11:46pm UTC](https://www.ruby-forum.com/t/studying-the-object-model/158874/1 "2009-01-28T23:46:31Z")

</div>

I’m looking for some study aid. I want to understand Ruby’s object model  
better.

Is there some tool that takes some object as input and shows its  
inheritance chain, it’s instance and class variables, the singleton  
classes and all?

I’ve already seen some diagrams that explain how OOP work in Ruby, but  
I’d still like to see all this in my own eyes.

---

<div class="post-metadata">

**Author:** ![alby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/85f322/32.png) [@alby](https://www.ruby-forum.com/u/alby)\
**Post date:** [January 29, 2009, 3:29am UTC](https://www.ruby-forum.com/t/studying-the-object-model/158874/2 "2009-01-29T03:29:39Z")

</div>

The Pragmatic screencast - Episode 1: Objects and Classes ($5.00, 29  
mins)does a good job explaining Ruby object model -

> **[Pragmatic Bookshelf: By Developers, For Developers](https://pragprog.com)**
>
> We improve the lives of professional developers. We create timely, practical books on classic and cutting-edge topics to help you learn and practice your craft, and accelerate your career. Come learn with us.

Hope that helps.

â€”

Satish T.  
RubyLearning  
Twitter: [http://twitter.com/IndianGuru](http://twitter.com/IndianGuru)

---

<div class="post-metadata">

**Author:** ![alby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/85f322/32.png) [@alby](https://www.ruby-forum.com/u/alby)\
**Post date:** [January 29, 2009, 6:03am UTC](https://www.ruby-forum.com/t/studying-the-object-model/158874/3 "2009-01-29T06:03:04Z")

</div>

On Thu, Jan 29, 2009 at 7:44 AM, Albert S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I’m looking for some study aid. I want to understand Ruby’s object model  
> better.
> 
> Is there some tool that takes some object as input and shows its  
> inheritance chain, it’s instance and class variables, the singleton  
> classes and all?
> 
> I’ve already seen some diagrams that explain how OOP work in Ruby, but  
> I’d still like to see all this in my own eyes.

There is no interactive tool I know of, but read following:

[http://jaoo.dk/ruby-cph-2008/file?path=/jaoo-ruby-cph-2008/slides/Dave\_Metaprogramming.pdf](http://jaoo.dk/ruby-cph-2008/file?path=/jaoo-ruby-cph-2008/slides/Dave_Metaprogramming.pdf)

(it’s free, unlike the screencast)

^ manveru

---

<div class="post-metadata">

**Author:** ![alby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/85f322/32.png) [@alby](https://www.ruby-forum.com/u/alby)\
**Post date:** [January 29, 2009, 9:16am UTC](https://www.ruby-forum.com/t/studying-the-object-model/158874/4 "2009-01-29T09:16:11Z")

</div>

2009/1/29 Justin C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > I’d still like to see all this in my own eyes.
> 
> I think you want something more visual than this (?) but you can always just  
> ask Ruby itself:

Here’s an easy way to get a visual graph of the currently defined  
class hierarchy:

ruby -r pp -e ‘tree = Hash.new {|h,k| h[k] = Hash.new(&h.default\_proc)}  
ObjectSpace.each\_object(Class) {|cl| tree[cl.superclass][cl] = tree[cl]}  
pp tree[Object]’

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![alby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/85f322/32.png) [@alby](https://www.ruby-forum.com/u/alby)\
**Post date:** [January 29, 2009, 6:14am UTC](https://www.ruby-forum.com/t/studying-the-object-model/158874/5 "2009-01-29T06:14:12Z")

</div>

Albert S. wrote:

> I’m looking for some study aid. I want to understand Ruby’s object model  
> better.
> 
> Is there some tool that takes some object as input and shows its  
> inheritance chain, it’s instance and class variables, the singleton  
> classes and all?
> 
> I’ve already seen some diagrams that explain how OOP work in Ruby, but  
> I’d still like to see all this in my own eyes.

I think you want something more visual than this (?) but you can always  
just ask Ruby itself:

irb(main):001:0\> s = String.new  
=\> “”  
irb(main):002:0\> s.class  
=\> String  
irb(main):003:0\> s.class.ancestors  
=\> [String, Enumerable, Comparable, Object, Kernel]  
irb(main):004:0\> s.public\_methods.sort  
=\> ["%", “\*”, “+”, “\<”, “\<\<”, “\<=”, “\<=\>”, “==”, “===”, “=~”, “\>”, “\>=”,  
“[]”, “[]=”, “ **id** ”, “ **send** ”, “all?”, “any?”, “between?”, “bytes”,  
“bytesize”, “capitalize”, “capitalize!”, “casecmp”, “center”, “chars”,  
“chomp”, “chomp!”, “chop”, “chop!”, “class”, “clone”, “collect”,  
“concat”, “count”, “crypt”, “cycle”, “delete”, “delete!”, “detect”,  
“display”, “downcase”, “downcase!”, “drop”, “drop\_while”, “dump”, “dup”,  
“each”, “each\_byte”, “each\_char”, “each\_cons”, “each\_line”,  
“each\_slice”, “each\_with\_index”, “empty?”, “end\_with?”, “entries”,  
“enum\_cons”, “enum\_for”, “enum\_slice”, “enum\_with\_index”, “eql?”,  
“equal?”, “extend”, “find”, “find\_all”, “find\_index”, “first”, “freeze”,  
“frozen?”, “grep”, “group\_by”, “gsub”, “gsub!”, “hash”, “hex”, “id”,  
“include?”, “index”, “inject”, “insert”, “inspect”, “instance\_eval”,  
“instance\_exec”, “instance\_of?”, “instance\_variable\_defined?”,  
“instance\_variable\_get”, “instance\_variable\_set”, “instance\_variables”,  
“intern”, “is\_a?”, “kind\_of?”, “length”, “lines”, “ljust”, “lstrip”,  
“lstrip!”, “map”, “match”, “max”, “max\_by”, “member?”, “method”,  
“methods”, “min”, “min\_by”, “minmax”, “minmax\_by”, “next”, “next!”,  
“nil?”, “none?”, “object\_id”, “oct”, “one?”, “partition”,  
“private\_methods”, “protected\_methods”, “public\_methods”, “reduce”,  
“reject”, “replace”, “respond\_to?”, “reverse”, “reverse!”,  
“reverse\_each”, “rindex”, “rjust”, “rpartition”, “rstrip”, “rstrip!”,  
“scan”, “select”, “send”, “singleton\_methods”, “size”, “slice”,  
“slice!”, “sort”, “sort\_by”, “split”, “squeeze”, “squeeze!”,  
“start\_with?”, “strip”, “strip!”, “sub”, “sub!”, “succ”, “succ!”, “sum”,  
“swapcase”, “swapcase!”, “taint”, “tainted?”, “take”, “take\_while”,  
“tap”, “test”, “to\_a”, “to\_enum”, “to\_f”, “to\_i”, “to\_s”, “to\_str”,  
“to\_sym”, “tr”, “tr!”, “tr\_s”, “tr\_s!”, “type”, “unpack”, “untaint”,  
“upcase”, “upcase!”, “upto”, “zip”]  
irb(main):005:0\> s.instance\_variables  
=\> []  
irb(main):006:0\> class \<\< s  
irb(main):007:1\> def test  
irb(main):008:2\> end  
irb(main):009:1\> end  
=\> nil  
irb(main):010:0\> s.singleton\_methods  
=\> [“test”]

-Justin
