From: Danny O cuiv Date: 2009-05-11T21:42:04+09:00 Subject: Re: Superclass of eigenclass Rick, Robert, Thanks again for your replies. Rick wrote: > If you go in and look at the implementation, you'll find that the > eigenclass of String has a superclass slot which points to the > eigenclass of Object, but the superclass method implementation skips > past 'singleton' classes, until it gets to To me, that smacks of being ad hoc and inconsistent. The superclass method implementation skips past 'singleton' classes, until it gets to #. But # is itself a 'singleton' class, so I can't see the rationale there. In other words, I can't really grasp what semantics are being exposed. Robert wrote: > But in reality singleton classes, yes that is what I prefer ;) are > very simple because you really never care too much about their > inheritance. The more I work with Ruby the less I care about > inheritance in general. I would disagree that one would never really care too much about an eigenclass's inheritance. Example 8-10 on page 294 of the Flanagan/Matz book details a very nice-looking technique for doing interception. (The particular example uses the technique to wrap tracing code.) This technique depends on accessing the original implementation of the method by calling super in an eigenclass, so the inheritance of the eigenclass is crucial here. In attempting to understand why this might work, I have four conflicting viewpoints. Say I have a class X that I instantiate to get a regular object x. Say that the eigenclass of x is e. For the interception technique to work, X needs to be above e in the inheritance hierarchy. (i) The Flanagan/Matz book says that an eigenclass of a regular object doesn't have a superclass. (So that e has no superclass.) Clearly this is incorrect. (ii) Exploring using the superclass method gives: e.superclass # => # e.superclass.superclass # => # e.superclass.superclass.superclass # => # with the same result for any further calls to superclass. This indicates that X is not in the inheritance hierarchy of e and consequently the technique should not work. (iii) Exploring using the ancestors method gives: e.ancestors # => [X, Object, Kernel] This indicates that X is in the inheritance hierarchy of e and consequently the technique should work. (iv) Exploring using is_a? x.is_a? e # => true This indicates that e is in the inheritance hierarchy of X (i.e. the opposite of the previous indication) and consequently the technique should not work. I'd have to confess that this seems like a conceptual mess to me. I presume that I'm grasping the wrong end of some stick or other. Can anyone help point out what that might be? Regards, Danny -- Posted via http://www.ruby-forum.com/.