Evening all,

So I am in the process of adding class-methods into the meta-model using eigenclasses. Eigenclasses are a ruby thing (and also a CLOS thing IIRC), in which an anon-class is inserted between an instance and it's class, essentially replacing the instance's class. The anon- class then adds the original class to it's superclass list. This is best shown visually I think:

    :  <-- eFoo is a subclass of Class
 ::eFoo   # eFoo is also an instance of Class
    |  <-- eFoo is the class of Foo

The dispatching of instance methods is still the same, and everything "just works". Well... almost everything.

There is a slight issue/inconsitency with how $?CLASS works.

class Foo {
    method bar (Class $c:)  { $?CLASS }
    method baz (Foo $self:) { $?CLASS }

Within the &bar class-method, the natural inclination is to think that $?CLASS will refer to ::Foo. However, in order to be consistent it actually refers to the eigenclass between ::Foo and ::Class, lets call it ::eFoo. This is because methods are associated with the class which contains them. In the &baz instance-method, $?CLASS does refer to ::Foo, since ::Foo is the class which contains &baz.

It seems to me that this inconsistency could be very problematic, especially since eigenclasses should really be an invisible implementation detail.

I am not 100% sure of what is the correct approach here, so I thought I would ask the group. Any thoughts guys/gals?



Reply via email to