Forum: Ruby Ruby Method Lookup Flow

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ec9233451f7c6ba37a83388b87a1f565?d=identicon&s=25 Phrogz (Guest)
on 2006-02-19 07:34
(Received via mailing list)
I sat down to diagram Ruby's object model in something better than
ascii, and ended up getting confused on how to label 'objects' or
'spaces' where methods lived. So instead, I diagrammed[1] the flow of
how method lookup works. I was surprised by a few findings, so I think
it was a nice exercise.

For your enjoyment and criticism, I give you:
http://phrogz.net/RubyLibs/RubyMethodLookupFlow.png

Gimme a holler if anything about it is wrong (inconceivable).

[1] Because people inevitably end up asking: it was diagrammed with
OmniGraffle, the prettiest and best damned diagramming software I've
ever used, available only for MacOS X.
Dd76a12d66f843de5c5f8782668e7127?d=identicon&s=25 Mauricio Fernandez (Guest)
on 2006-02-19 11:23
(Received via mailing list)
On Sun, Feb 19, 2006 at 03:33:29PM +0900, Phrogz wrote:
> I sat down to diagram Ruby's object model in something better than
> ascii, and ended up getting confused on how to label 'objects' or
> 'spaces' where methods lived. So instead, I diagrammed[1] the flow of
> how method lookup works. I was surprised by a few findings, so I think
> it was a nice exercise.
>
> For your enjoyment and criticism, I give you:
> http://phrogz.net/RubyLibs/RubyMethodLookupFlow.png
>
> Gimme a holler if anything about it is wrong (inconceivable).

The unimaginable happens.

"All method lookups include, and finish at, the Object metaclass."

Object includes Kernel...
Also, s/metaclass//.

Maybe you could insert another module between Square and Rect, as in

class A; def foo; "A#foo" end end
class B < A; end
module C; def foo; "C#foo" end end
b = B.new
b.foo                                              # => "A#foo"
class B; include C end
b.foo                                              # => "C#foo"

in order to show that modules can shadow instance methods defined in
classes
and that there's no special rule to make them float right below Object
or
anything like that.
Ec9233451f7c6ba37a83388b87a1f565?d=identicon&s=25 Phrogz (Guest)
on 2006-02-19 13:48
(Received via mailing list)
Excellent points, all. Updated. Reload. :)
12271b6df73fe29930d65586be5a4a70?d=identicon&s=25 Dave Howell (Guest)
on 2006-02-19 22:05
(Received via mailing list)
On Feb 19, 2006, at 4:48, Phrogz wrote:

> Excellent points, all. Updated. Reload. :)
>

It looks very meaningful. :) Alas, I'm confused. When I get to (for
example), the "class Square < Rect" pair of boxes, which arrow do I
follow when exiting, and why? Are they parts of the same definition, or
two different definitions? If class Square doesn't "include Regular"
then do I just follow the left-hand exit arrow? Is the "def
square1.meth" box one of these "singleton" methods I've read about?
Ec9233451f7c6ba37a83388b87a1f565?d=identicon&s=25 Phrogz (Guest)
on 2006-02-20 06:00
(Received via mailing list)
Not to bump my own thread, but I've updated the diagram again - was
able to compress a lot of vertical space for the main diagram, and add
some informative notes calling out interesting/important aspects.

It's not (just) that I crave attention that I post this, but I really
want to make sure that there's nothing wrong or misleading with the
diagram. Having an incorrect diagram (*cough* ilias *cough*) on the web
would be far worse than having no diagram at all.
Ec9233451f7c6ba37a83388b87a1f565?d=identicon&s=25 Phrogz (Guest)
on 2006-02-20 06:49
(Received via mailing list)
Oh, and: I added a PDF version of the diagram also, for those
interested in clean printing.
http://phrogz.net/RubyLibs/RubyMethodLookupFlow.pdf

I now return you to your regular signal-to-noise ratio.
This topic is locked and can not be replied to.