[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Ruby Method Lookup Flow

Gavin Kistner

2/19/2006 6:32:00 AM

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/RubyMethodLook...

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.

--
(-, /\ \/ / /\/

4 Answers

Mauricio Fernández

2/19/2006 10:22:00 AM

0

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/RubyMethodLook...
>
> 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.

--
Mauricio Fernandez - http://eige... - non-trivial Ruby


Gavin Kistner

2/19/2006 12:44:00 PM

0

Excellent points, all. Updated. Reload. :)

Gavin Kistner

2/20/2006 4:55:00 AM

0

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.

Gavin Kistner

2/20/2006 5:40:00 AM

0

Oh, and: I added a PDF version of the diagram also, for those
interested in clean printing.
http://phrogz.net/RubyLibs/RubyMethodLook...

I now return you to your regular signal-to-noise ratio.