# Class hierarchy with rdoc

**URL:** <https://www.ruby-forum.com/t/class-hierarchy-with-rdoc/91359>\
**Category:** Ruby\
**Created:** [April 7, 2007, 2:25pm UTC](https://www.ruby-forum.com/t/class-hierarchy-with-rdoc/91359 "2007-04-07T14:25:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Googy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/dfb087/32.png) [@Googy](https://www.ruby-forum.com/u/Googy)\
**Post date:** [April 7, 2007, 2:25pm UTC](https://www.ruby-forum.com/t/class-hierarchy-with-rdoc/91359/1 "2007-04-07T14:25:35Z")

</div>

Hi,

I am newbie to ruby, I have extensive experience in java & with  
javadoc, javadoc shows class hierarchy i.e. its parent classes and  
interfaces in a tree view, so you can easily understand the whole  
hierarchy but when I moved to ruby the feature missing is to see the  
class hierarchy for ruby classes. Every time I can’t fire irb and  
create an object and see its ancestors  
(.class. ancestors).

So am I missing something? Is it possible to see the class hierarchy  
in rdoc generated documentation ?

Particularly when you go to [http://www.ruby-doc.org/core/](http://www.ruby-doc.org/core/) for core  
documentation there is no way to see even Fixnum parent classes.  
Fixnum is only for example. And from my experience good  
documentation plays important role in its adaptability.

Suggest me if there are any alternative ruby documentation generators  
or class browsers.

Thanks.

---

<div class="post-metadata">

**Author:** ![Googy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/dfb087/32.png) [@Googy](https://www.ruby-forum.com/u/Googy)\
**Post date:** [April 7, 2007, 2:47pm UTC](https://www.ruby-forum.com/t/class-hierarchy-with-rdoc/91359/2 "2007-04-07T14:47:38Z")

</div>

Alle sabato 7 aprile 2007, Googy ha scritto:

> So am I missing something? Is it possible to see the class hierarchy  
> Thanks.  
> RDoc doesn’t allow you to see the full class hierarchy, but it does  
> allow you  
> to see the parent class of a given class. It’s specified just below the  
> name  
> of the class. Taking Fixnum as an example, at the beginning of the  
> documentation page, there is:

Class Fixnum  
In: numeric.c  
lib/mathn.rb  
lib/rational.rb  
lib/rexml/xpath\_parser.rb  
Parent: Integer

This last line is the one you need. It tells you that the parent class  
of  
Fixnum is Integer.

You can also see it using ri: if you type, for example:

ri Fixnum,

the very first line you get says:

Class: Fixnum \< Integer

which tells you the parent of Fixnum. If no parent is displayed, it  
means that  
the class inherit directly from Object.

I hope this helps

Stefano

---

<div class="post-metadata">

**Author:** ![Googy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/dfb087/32.png) [@Googy](https://www.ruby-forum.com/u/Googy)\
**Post date:** [April 7, 2007, 3:01pm UTC](https://www.ruby-forum.com/t/class-hierarchy-with-rdoc/91359/3 "2007-04-07T15:01:39Z")

</div>

@Stefano C.  
Thanks, I overlooked it.

@Scott T.  
Thanks for suggesting ri.

---

<div class="post-metadata">

**Author:** ![Googy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/dfb087/32.png) [@Googy](https://www.ruby-forum.com/u/Googy)\
**Post date:** [April 7, 2007, 2:48pm UTC](https://www.ruby-forum.com/t/class-hierarchy-with-rdoc/91359/4 "2007-04-07T14:48:38Z")

</div>

Use ri ‘ClassName’ at the command line.

A better alternative is to download the fast-ri gem (ri is incredibly  
slow).

Just to let you know, Ruby does not have multiple Inheritance, so  
most of the base classes subclass from class Object. What you are  
seeing when you call “ancestors” are the modules which are included  
in the class. All of this information is given to you through ri.

If you are looking for rdoc documentation, use the gem\_server command  
at the command line and go to [http://localhost:8808/](http://localhost:8808/). That should  
give you the docs for any gems you have installed on your system.

Hope that helps,

Scott T.

---

<div class="post-metadata">

**Author:** ![Googy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/dfb087/32.png) [@Googy](https://www.ruby-forum.com/u/Googy)\
**Post date:** [April 7, 2007, 5:25pm UTC](https://www.ruby-forum.com/t/class-hierarchy-with-rdoc/91359/5 "2007-04-07T17:25:50Z")

</div>

Googy [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> @Stefano C.  
> Thanks, I overlooked it.
> 
> @Scott T.  
> Thanks for suggesting ri.

Also I find it useful to have on hand a little utility for generating a  
report about a class’s ancestry, such as this:

def method\_report(klass)  
result = klass.ancestors.inject(Array.new) do |result, anc|  
ms = (anc.instance\_methods + anc.methods).sort.uniq  
result.last[1] -= ms if result.last  
result \<\< [anc.name, ms]  
end  
result.each do |k, v|  
puts “----”, k  
v.each {|m| puts “\s\s#{m}”}  
end  
end

# and here’s how to use it

method\_report(File)

That’s basically what you were already doing in irb, but going a little  
further. 🙂 HTH - m.
