The Ruby Object Model


#1

It seems that Ruby lacks the diagram of a core object model. The only
helpful article I found was
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

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:
http://rubylangfindings.blogspot.com/2013/12/ruby-core-object-model.html)


#2

On Mon, Dec 2, 2013 at 4:07 PM, Artem S. removed_email_address@domain.invalid wrote:

I can update this diagram (I will post updated version at this page:
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.


#3

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


#4

On Mon, Dec 2, 2013 at 4:40 PM, Jess Gabriel y Galn
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.


#5

This is updated version:

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?


#6

On Mon, Dec 2, 2013 at 5:12 PM, Artem S. removed_email_address@domain.invalid wrote:

This is updated version:

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.


#7

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 <


#8

On Wed, Dec 4, 2013 at 8:36 AM, Artem S. 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


#9

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.


#10

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

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


#11

Am Mon, 02 Dec 2013 17:12:52 +0100
schrieb “Artem S.” removed_email_address@domain.invalid:

This is updated version:

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

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://gnupg.org/index.de.html


#12

Hans, thank you, corrected.


#13

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


#14

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 as when I correct any mistakes,
all of them update there automatically.


#15

“unknown”, ENV and ARGF were taken from 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.


#16

On Dec 5, 2013, at 3:45, Artem S. 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 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).


#17

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/

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 as the official info source, you’ll note that
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.


#18

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. :wink:


#19

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.