B
Ben Tompkins
This is the correct title, uh, I think...
dyslexic me
dyslexic me
This is the correct title, uh, I think...
dyslexic me
Marcin said:The << direction is correct (and intuitive IMHO), given:
class A < B
end
This can do two things, either creates and opens class A extending class
B or reopens class A if it already exits=20
[...]
class << s
end
What this does ? it either creates and opens singleton class for s
instance or reopens the singleton it if it already exits. Since
singleton classes dont have their names you could also imagine
<anonyous_name> between class and << tokens here.
I like it when people agree with me, and according to the diagram on
page 384 of Programming Ruby, you are basically correct to say that
"self inherits from the singleton class." The diagram shows that a
"virtual" (singleton) class is inserted into the inheritance hierarchy
for self (or whatever the RHS happens to be) as an immediate subclass of
the most derived, non-singleton, class of which the RHS is an instance
whenever 'class << RHS ...' is executed. So even if we think of the '<<'
as an "inheritance operator," it is still pointing in the wrong
direction! But is inheritance really the right concept here? Notice that
the singleton class is inserted below the most specific class of the RHS
term. If the RHS were the same as its class (which is impossible), then
Marcin would be right, because the singleton class would be subclassing
the RHS. But no instance is ever the same as its class. What is really
going on is that we are
augmenting the interface of the RHS by decorating its most derived class
with an anonymous class to which RHS has exclusive access, thus
effectively adding the methods of the singleton class to the RHS. As the
recipient of these new methods, RHS is on the receiving side of the
operation, which is why 'class >> RHS ...' is more intuitive than 'class
<< RHS ... .'
Perhaps you were misled by the first sentence of my reply to Sebastian,unknown said:Hi --
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.