# The Ruby Object Model

**URL:** <https://www.ruby-forum.com/t/the-ruby-object-model/237824>\
**Category:** Ruby\
**Created:** [December 2, 2013, 4:07pm UTC](https://www.ruby-forum.com/t/the-ruby-object-model/237824 "2013-12-02T16:07:57Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [December 2, 2013, 4:07pm UTC](https://www.ruby-forum.com/t/the-ruby-object-model/237824/1 "2013-12-02T16:07:57Z")

</div>

It seems that Ruby lacks the diagram of a core object model. The only  
helpful article I found was  
[A diagram of the Ruby Core object model - Jerome's Adventures in Software](http://jeromedalbert.com/a-diagram-of-the-ruby-core-object-model/), but  
it doesn’t include some classes and some words are not so easy to read.

So I tried to make good visualization and created this diagram:

[![](https://lh4.googleusercontent.com/e_Eml6aYg1udItOLjQCzUKF1L2K1JcjyZTnzYwcP7A=w1530-h800-no) ](https://lh4.googleusercontent.com/e_Eml6aYg1udItOLjQCzUKF1L2K1JcjyZTnzYwcP7A=w1530-h800-no)

I hope it will be helpful. If you find any mistakes please inform me so  
I can update this diagram (I will post updated version at this page:  
[Ruby Findings: Ruby Core Object Model](http://rubylangfindings.blogspot.com/2013/12/ruby-core-object-model.html))

---

<div class="post-metadata">

**Author:** ![ainstainer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@ainstainer](https://www.ruby-forum.com/u/ainstainer)\
**Post date:** [December 2, 2013, 4:41pm UTC](https://www.ruby-forum.com/t/the-ruby-object-model/237824/2 "2013-12-02T16:41:21Z")

</div>

On Mon, Dec 2, 2013 at 4:07 PM, Artem S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I can update this diagram (I will post updated version at this page:  
> [Ruby Findings: Ruby Core Object Model](http://rubylangfindings.blogspot.com/2013/12/ruby-core-object-model.html))

Nice !

I have a couple questions, though:

- I think there’s a red arrow missing between the block that includes  
IO, Dir and File::Stat to Object, if I understand correctly. I’m not  
so sure about ARGF, it seems to be a special thing:

2.0.0-p195 :011 \> ARGF.class  
=\> ARGF.class  
2.0.0-p195 :010 \> ARGF.superclass  
NoMethodError: undefined method `superclass’ for ARGF:ARGF.class

I guess I’ll have to read a bit more about it.

- The same for the rounded classes that are outside boxes, such as  
String, Symbol, Random, Date and Time.

- String and Time include Comparable.

- IO includes File::Constants

- I find it confusing that the only green arrows are between Module  
and Class, and between Class and itself. I guess drawing an arrow  
between all classes and Class is too cumbersome. If that’s true and  
that’s the reason you drew the green background to represent that,  
then you should remove the link from Class to itself, since Class sits  
in the green background too, so it would be implied.

- Similar for the blue arrows.

Thanks for this work, it’s great.

Jesus.

---

<div class="post-metadata">

**Author:** ![ainstainer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@ainstainer](https://www.ruby-forum.com/u/ainstainer)\
**Post date:** [December 2, 2013, 4:45pm UTC](https://www.ruby-forum.com/t/the-ruby-object-model/237824/3 "2013-12-02T16:45:08Z")

</div>

Jesus, thank you for good recomendations, I will make an update soon.

---

<div class="post-metadata">

**Author:** ![ainstainer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@ainstainer](https://www.ruby-forum.com/u/ainstainer)\
**Post date:** [December 2, 2013, 5:11pm UTC](https://www.ruby-forum.com/t/the-ruby-object-model/237824/4 "2013-12-02T17:11:45Z")

</div>

On Mon, Dec 2, 2013 at 4:40 PM, Jess Gabriel y Galn  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m not so sure about ARGF, it seems to be a special thing:
> 
> 2.0.0-p195 :011 \> ARGF.class  
> =\> ARGF.class  
> 2.0.0-p195 :010 \> ARGF.superclass  
> NoMethodError: undefined method `superclass’ for ARGF:ARGF.class
> 
> I guess I’ll have to read a bit more about it.

Just for my own education: ARGF is an object of a class that is  
defined inside io.c (MRI). That class is named ARGF.class

```
rb_cARGF = rb_class_new(rb_cObject);
rb_set_class_path(rb_cARGF, rb_cObject, "ARGF.class");

```

The first line creates an anonymous class that inherits from Object.  
The second line is a bit magical for me, but based on my tests it  
seems to tell Ruby that the class name is “ARGF.class”:

2.0.0-p195 :003 \> ARGF.send :class  
=\> ARGF.class

It includes Enumerable:

2.0.0-p195 :006 \> ARGF.class.ancestors  
=\> [ARGF.class, Enumerable, Object, Kernel, BasicObject]

So, summary: ARGF is an object of class ARGF.class. As to why this is  
implemented in such way instead of a regular class, I don’t know, but  
there’s a hack in the code to make rdoc treat the object itself as a  
class:

#if 0  
/\* Hack to get rdoc to regard ARGF as a class: \*/  
rb\_cARGF = rb\_define\_class(“ARGF”, rb\_cObject);  
#endif

This makes it confusing also, since if you check the documentation  
you’d think that ARGF is actually a class when it isn’t.

Jesus.

---

<div class="post-metadata">

**Author:** ![ainstainer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@ainstainer](https://www.ruby-forum.com/u/ainstainer)\
**Post date:** [December 2, 2013, 5:12pm UTC](https://www.ruby-forum.com/t/the-ruby-object-model/237824/5 "2013-12-02T17:12:52Z")

</div>

This is updated version:

[![](https://lh3.googleusercontent.com/-CwmrmMaIeqg/Upywjx1vdBI/AAAAAAAAAm0/2qZBmOZFL-0/s1530/Ruby.png) ](https://lh3.googleusercontent.com/-CwmrmMaIeqg/Upywjx1vdBI/AAAAAAAAAm0/2qZBmOZFL-0/s1530/Ruby.png)

I think I should change something because of many red lines.

And I didn’t understand about “- Similar for the blue arrows.” — Module  
doesn’t unclude self arrows. Is is correct on updated version?

---

<div class="post-metadata">

**Author:** ![ainstainer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@ainstainer](https://www.ruby-forum.com/u/ainstainer)\
**Post date:** [December 2, 2013, 5:21pm UTC](https://www.ruby-forum.com/t/the-ruby-object-model/237824/6 "2013-12-02T17:21:42Z")

</div>

On Mon, Dec 2, 2013 at 5:12 PM, Artem S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> This is updated version:

[![](https://lh3.googleusercontent.com/-CwmrmMaIeqg/Upywjx1vdBI/AAAAAAAAAm0/2qZBmOZFL-0/s1530/Ruby.png) ](https://lh3.googleusercontent.com/-CwmrmMaIeqg/Upywjx1vdBI/AAAAAAAAAm0/2qZBmOZFL-0/s1530/Ruby.png)

> I think I should change something because of many red lines.
> 
> And I didn’t understand about “- Similar for the blue arrows.” Module  
> doesn’t unclude self arrows. Is is correct on updated version?

Sorry, you are right. I was mistaken here.

Regarding the new version, I think it’s fine, there are not too many  
arrows, in my opinion.

Jesus.

---

<div class="post-metadata">

**Author:** ![ainstainer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@ainstainer](https://www.ruby-forum.com/u/ainstainer)\
**Post date:** [December 4, 2013, 1:38am UTC](https://www.ruby-forum.com/t/the-ruby-object-model/237824/7 "2013-12-04T01:38:17Z")

</div>

I want to make one. How do I do that? I want to make an interactive one!

On Mon, Dec 2, 2013 at 10:21 AM, Jess Gabriel y Galn \<

---

<div class="post-metadata">

**Author:** ![ainstainer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@ainstainer](https://www.ruby-forum.com/u/ainstainer)\
**Post date:** [December 4, 2013, 8:39am UTC](https://www.ruby-forum.com/t/the-ruby-object-model/237824/8 "2013-12-04T08:39:49Z")

</div>

On Wed, Dec 4, 2013 at 8:36 AM, Artem S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> UnfortunatelyI can’t say what tool should you use to create interactive  
> diagram. Maybe something like Visio? I didn’t work with such kind of  
> tools.

Artem, you could generate SVG - it has some interactive capabilities.  
Or HTML5.

Cheers

robert

---

<div class="post-metadata">

**Author:** ![ainstainer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@ainstainer](https://www.ruby-forum.com/u/ainstainer)\
**Post date:** [December 4, 2013, 8:36am UTC](https://www.ruby-forum.com/t/the-ruby-object-model/237824/9 "2013-12-04T08:36:39Z")

</div>

UnfortunatelyI can’t say what tool should you use to create interactive  
diagram. Maybe something like Visio? I didn’t work with such kind of  
tools.

---

<div class="post-metadata">

**Author:** ![ainstainer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@ainstainer](https://www.ruby-forum.com/u/ainstainer)\
**Post date:** [December 4, 2013, 8:46am UTC](https://www.ruby-forum.com/t/the-ruby-object-model/237824/10 "2013-12-04T08:46:52Z")

</div>

Yes, it is possible to export from Gliffy to svg, but the problem is  
that I can’t edit svg within Gliffy. I can edit svg file and add some  
interactivity, but I lose the possibility to correct any mistakes in the  
diagram itself.

[http://www.gliffy.com/go/publish/5152080](http://www.gliffy.com/go/publish/5152080)

I think the best way is to use another more sophisticated tool.

---

<div class="post-metadata">

**Author:** ![ainstainer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@ainstainer](https://www.ruby-forum.com/u/ainstainer)\
**Post date:** [December 5, 2013, 12:27pm UTC](https://www.ruby-forum.com/t/the-ruby-object-model/237824/11 "2013-12-05T12:27:30Z")

</div>

Am Mon, 02 Dec 2013 17:12:52 +0100  
schrieb “Artem S.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> This is updated version:

[![](https://lh3.googleusercontent.com/-CwmrmMaIeqg/Upywjx1vdBI/AAAAAAAAAm0/2qZBmOZFL-0/s1530/Ruby.png) ](https://lh3.googleusercontent.com/-CwmrmMaIeqg/Upywjx1vdBI/AAAAAAAAAm0/2qZBmOZFL-0/s1530/Ruby.png)

This graphic looks great. What license is it under? Can we have this as  
PDF with real text?

Vale,  
Quintus

–  
Blog: [http://www.quintilianus.eu](http://www.quintilianus.eu)

I will reject HTML emails. | Ich akzeptiere keine HTML-Nachrichten.  
|  
Use GnuPG for mail encryption: | GnuPG für Mail-Verschlüsselung:  
[http://www.gnupg.org](http://www.gnupg.org) | [The GNU Privacy Guard](http://gnupg.org/index.de.html)

---

<div class="post-metadata">

**Author:** ![ainstainer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@ainstainer](https://www.ruby-forum.com/u/ainstainer)\
**Post date:** [December 5, 2013, 12:37pm UTC](https://www.ruby-forum.com/t/the-ruby-object-model/237824/12 "2013-12-05T12:37:37Z")

</div>

Hans, thank you, corrected.

---

<div class="post-metadata">

**Author:** ![ainstainer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@ainstainer](https://www.ruby-forum.com/u/ainstainer)\
**Post date:** [December 5, 2013, 12:30pm UTC](https://www.ruby-forum.com/t/the-ruby-object-model/237824/13 "2013-12-05T12:30:25Z")

</div>

File::Stat does not include Enumerable, it does include Comparable so  
its in the wrong group

---

<div class="post-metadata">

**Author:** ![ainstainer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@ainstainer](https://www.ruby-forum.com/u/ainstainer)\
**Post date:** [December 5, 2013, 12:45pm UTC](https://www.ruby-forum.com/t/the-ruby-object-model/237824/14 "2013-12-05T12:45:43Z")

</div>

Quintus, do what you what to do. WTFPL license.

I recommend you use not png version, but updated version on  
[http://www.gliffy.com/go/publish/5152080](http://www.gliffy.com/go/publish/5152080) as when I correct any mistakes,  
all of them update there automatically.

---

<div class="post-metadata">

**Author:** ![ainstainer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@ainstainer](https://www.ruby-forum.com/u/ainstainer)\
**Post date:** [December 5, 2013, 10:57pm UTC](https://www.ruby-forum.com/t/the-ruby-object-model/237824/15 "2013-12-05T22:57:18Z")

</div>

“unknown”, ENV and ARGF were taken from [http://ruby-doc.org/core-2.0/](http://ruby-doc.org/core-2.0/)

If it is incorrect, I would expect for correction on the official site  
at first.

Thanks for information.

---

<div class="post-metadata">

**Author:** ![ainstainer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@ainstainer](https://www.ruby-forum.com/u/ainstainer)\
**Post date:** [December 5, 2013, 10:46pm UTC](https://www.ruby-forum.com/t/the-ruby-object-model/237824/16 "2013-12-05T22:46:18Z")

</div>

On Dec 5, 2013, at 3:45, Artem S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Vale, do what you what to do. WTFPL license.
> 
> I recommend you use not png version, but updated version on  
> [http://www.gliffy.com/go/publish/5152080](http://www.gliffy.com/go/publish/5152080) as when I correct any mistakes,  
> all of them update there automatically.

I have no idea what the one green line is supposed to represent.

Module is a class, not a module.

There is no class named “unknown”.

ENV is an instance, not a class.

Same with ARGF (tho it’s an oddity when you ask for its class).

---

<div class="post-metadata">

**Author:** ![ainstainer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@ainstainer](https://www.ruby-forum.com/u/ainstainer)\
**Post date:** [December 5, 2013, 11:41pm UTC](https://www.ruby-forum.com/t/the-ruby-object-model/237824/17 "2013-12-05T23:41:57Z")

</div>

Ryan D. wrote in post #1129771:

> I have no idea what the one green line is supposed to represent.
> 
> Module is a class, not a module.

Yeah, I think that’s what the one green line is supposed to represent.  
(I.e. the inverse relationship of a red edge.)

> There is no class named “unknown”.
> 
> ENV is an instance, not a class.
> 
> Same with ARGF (tho it’s an oddity when you ask for its class).

Artem S. wrote in post #1129771:

> “unknown”, ENV and ARGF were taken from [http://ruby-doc.org/core-2.0/](http://ruby-doc.org/core-2.0/)
> 
> If it is incorrect, I would expect for correction on the official  
> site at first.

That’s a bit of a presumptuous statement. Knowingly perpetuating known  
bugs just because they’re on the “official” source doesn’t make them any  
less buggy or incorrect.

As I understand it, “unknown” is the result of uncertainty in rdoc when  
scanning combinations of C and ruby sources. If you’re taking  
[ruby-doc.org](http://ruby-doc.org) as the official info source, you’ll note that  
[http://ruby-doc.org/core-2.0/unknown.html](http://ruby-doc.org/core-2.0/unknown.html) doesn’t list any methods,  
subclasses, inclusions, etc. It’s not a real thing. It’s also useless  
information in the diagram, because “unknown” (with a small “u”) is a  
variable which is undefined (even when you trick the parser into  
acknowledging that it’s a variable – not a function – in the first  
place.)

if false; unknown=42; end  
unknown  
#=\> nil

Granted, the site does seem to list ENV as a class (it has a grey C  
beside it), but you’ll note that in ruby:

ENV.class == Object

…and:

class X \< ENV; end  
#=\> TypeError: superclass must be a Class (Object given)

class Y; include ENV; end  
#=\> TypeError: wrong argument type Object (expected Module)

Similarly for ARGF, but its class has a weird name.

The diagram seems to suggest that anything in the big green box can have  
a red arrow head (“class a \< b”), and anything in the big blue box can  
have a blue arrow head (“include b”), with the slightly confusing  
exceptions of Module and Class. But for unknown, ENV, and ARGF that  
isn’t true. Correct, precise, or otherwise, their value in the diagram  
is questionable.

---

<div class="post-metadata">

**Author:** ![ainstainer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@ainstainer](https://www.ruby-forum.com/u/ainstainer)\
**Post date:** [December 6, 2013, 12:45am UTC](https://www.ruby-forum.com/t/the-ruby-object-model/237824/18 "2013-12-06T00:45:04Z")

</div>

Artem S. wrote in post #1129781:

> > The diagram seems to suggest that anything in the big green box can have  
> > a red arrow head (“class a \< b”), and anything in the big blue box can  
> > have a blue arrow head (“include b”), with the slightly confusing  
> > exceptions of Module and Class.
> 
> Unfortunately I didn’t understand what you think is wrong here. It is  
> just  
> String.superclass =\> Object

I never said it was wrong. 😉

---

<div class="post-metadata">

**Author:** ![ainstainer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@ainstainer](https://www.ruby-forum.com/u/ainstainer)\
**Post date:** [December 6, 2013, 12:25am UTC](https://www.ruby-forum.com/t/the-ruby-object-model/237824/19 "2013-12-06T00:25:27Z")

</div>

> The diagram seems to suggest that anything in the big green box can have  
> a red arrow head (“class a \< b”), and anything in the big blue box can  
> have a blue arrow head (“include b”), with the slightly confusing  
> exceptions of Module and Class.

Unfortunately I didn’t understand what you think is wrong here. It is  
just  
String.superclass =\> Object

here, for example

But for unknown, ENV, and ARGF that

> isn’t true. Correct, precise, or otherwise, their value in the diagram  
> is questionable.

Ok, I deleted these objects.
