Re: What's the correct way to create anonymous subclasses in Pharo?
Posted by
Joachim Geidel on
May 23, 2010; 1:38pm
URL: https://forum.world.st/What-s-the-correct-way-to-create-anonymous-subclasses-in-Pharo-tp2227809p2227840.html
Re: [Pharo-users] What's the correct way to create anonymous subclasses in Pharo?
Am 23.05.10 15:15 schrieb Igor Stasenko:
> Do you really need to create a meta?
>
> If not , then you can do just:
>
> newClass := Rectangle clone.
> newClass
> superclass: Rectangle;
> organization: nil;
> methodDict: MethodDictionary new.
Unfortunately, this doesn’t solve the problem:
| newClass method |
newClass := Rectangle clone.
newClass
superclass: Rectangle;
organization: nil;
methodDict: MethodDictionary new;
setName: #MyRectangle.
newClass new class name. "--> #Rectangle"
newClass new class == newClass. "--> false"
method := (newClass compile: 'testGhost ^42'
classified: nil
notifying: nil
trailer: newClass defaultMethodTrailer
ifFail: [nil]) method.
newClass addSelectorSilently: #testGhost withMethod: method.
newClass canUnderstand: #testGhost. "--> true".
newClass new respondsTo: #testGhost. "--> false"
newClass new testGhost. "--> Message not understood, should answer 42"
The problem is not the MetaClass (I do need it), but that the new class doesn’t create instances of itself, which I find very, very strange.
Best regards,
Joachim Geidel
_______________________________________________
Pharo-users mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users