15 May 04:25
Method lookup for modules included in modules
From: Mark Wilden <mark <at> mwilden.com>
Subject: Method lookup for modules included in modules
Newsgroups: gmane.comp.lang.ruby.general
Date: 2008-05-15 02:29:02 GMT
Subject: Method lookup for modules included in modules
Newsgroups: gmane.comp.lang.ruby.general
Date: 2008-05-15 02:29:02 GMT
My question has to do with the diagram on page 12 of "Advanced Rails". It arises from the following structure: module A; end; module B; include A; end module C; include A; end class D; include B; include C; end (This would be a diamond-shaped hierarchy if inheritance were used.) Now picture a similar structure, except without a common ancestor: module A1; end; module A2; end; module B; include A1; end module C; include A2; end class D; include C; include B; end d = D.new When a message is sent to d, that method is searched for in the following order: B, A1, C, A2. My question is how this is implemented in terms of 'klass' and 'super' as described in the book. First, the klass pointer from d takes us to D, whose m_tbl is searched. Then D's super pointer takes us to the proxy for the B module. That proxy's m_tbl pointer points to the B methods which are searched. Then B's super pointer takes us to B's proxy for the A1 module, which causes A1's methods to be search. Here's my problem. If A1 doesn't contain the method, what causes the(Continue reading)
RSS Feed