Forum: Ruby The Ruby Object Model

925c1727856b5a3a15542b4d2ec85079?d=identicon&s=25 Artem S. (oclasoca)
on 2013-12-02 16:07
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-cor..., 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_Eml6aYg1udItOL...

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-...)
E088bb5c80fd3c4fd02c2020cdacbaf0?d=identicon&s=25 "Jesús Gabriel y Galán" <jgabrielygalan@gmail.com> (Guest)
on 2013-12-02 16:41
(Received via mailing list)
On Mon, Dec 2, 2013 at 4:07 PM, Artem S. <lists@ruby-forum.com> wrote:
> I can update this diagram (I will post updated version at this page:
> http://rubylangfindings.blogspot.com/2013/12/ruby-...)

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.
925c1727856b5a3a15542b4d2ec85079?d=identicon&s=25 Artem S. (oclasoca)
on 2013-12-02 16:45
Jesus, thank you for good recomendations, I will make an update soon.
E088bb5c80fd3c4fd02c2020cdacbaf0?d=identicon&s=25 "Jesús Gabriel y Galán" <jgabrielygalan@gmail.com> (Guest)
on 2013-12-02 17:11
(Received via mailing list)
On Mon, Dec 2, 2013 at 4:40 PM, Jess Gabriel y Galn
<jgabrielygalan@gmail.com> 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.
925c1727856b5a3a15542b4d2ec85079?d=identicon&s=25 Artem S. (oclasoca)
on 2013-12-02 17:12
This is updated version:

https://lh3.googleusercontent.com/-CwmrmMaIeqg/Upy...

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?
E088bb5c80fd3c4fd02c2020cdacbaf0?d=identicon&s=25 "Jesús Gabriel y Galán" <jgabrielygalan@gmail.com> (Guest)
on 2013-12-02 17:21
(Received via mailing list)
On Mon, Dec 2, 2013 at 5:12 PM, Artem S. <lists@ruby-forum.com> wrote:
> This is updated version:
>
>
https://lh3.googleusercontent.com/-CwmrmMaIeqg/Upy...
>
> 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.
9a45896e48a382fe5c656b8873e0dfcb?d=identicon&s=25 Stu (Guest)
on 2013-12-04 01:38
(Received via mailing list)
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 <
925c1727856b5a3a15542b4d2ec85079?d=identicon&s=25 Artem S. (oclasoca)
on 2013-12-04 08:36
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.
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (robert_k78)
on 2013-12-04 08:39
(Received via mailing list)
On Wed, Dec 4, 2013 at 8:36 AM, Artem S. <lists@ruby-forum.com> 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
925c1727856b5a3a15542b4d2ec85079?d=identicon&s=25 Artem S. (oclasoca)
on 2013-12-04 08:46
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.
85991f138ede6236f35eb98da22b7b01?d=identicon&s=25 Marvin Gülker (quintus)
on 2013-12-05 12:27
(Received via mailing list)
Attachment: signature.asc (489 Bytes)
Am Mon, 02 Dec 2013 17:12:52 +0100
schrieb "Artem S." <lists@ruby-forum.com>:

> This is updated version:
>
>
https://lh3.googleusercontent.com/-CwmrmMaIeqg/Upy...

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
D9ebdcb66f1583378e6f72155db507e2?d=identicon&s=25 Hans Mackowiak (hanmac)
on 2013-12-05 12:30
File::Stat does not include Enumerable, it does include Comparable so
its in the wrong group
925c1727856b5a3a15542b4d2ec85079?d=identicon&s=25 Artem S. (oclasoca)
on 2013-12-05 12:37
Hans, thank you, corrected.
925c1727856b5a3a15542b4d2ec85079?d=identicon&s=25 Artem S. (oclasoca)
on 2013-12-05 12:45
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.
5a837592409354297424994e8d62f722?d=identicon&s=25 Ryan Davis (Guest)
on 2013-12-05 22:46
(Received via mailing list)
On Dec 5, 2013, at 3:45, Artem S. <lists@ruby-forum.com> 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).
925c1727856b5a3a15542b4d2ec85079?d=identicon&s=25 Artem S. (oclasoca)
on 2013-12-05 22:57
"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.
3df767279ce7d81db0a5bb30f5136863?d=identicon&s=25 Matthew Kerwin (mattyk)
on 2013-12-05 23:41
Ryan Davis 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.
925c1727856b5a3a15542b4d2ec85079?d=identicon&s=25 Artem S. (oclasoca)
on 2013-12-06 00:25
> 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.
3df767279ce7d81db0a5bb30f5136863?d=identicon&s=25 Matthew Kerwin (mattyk)
on 2013-12-06 00:45
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. ;)
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.