(Newbee) Thoughts about removing class with code
Peter Crowther
Peter at ozzard.org
Mon Nov 14 23:00:04 UTC 2005
> From: [...] Marcus Pedersén
> I have a tempVariable (String) holding the name of my class that I want to "delete".
> But how do I get hold of the class so I can remove it?
Marcus, you need to distinguish three things:
- The object's identity; in this case, the class.
- The object's name; in this case, a Symbol naming the class. A Symbol is not a String. There's guaranteed only to be one Symbol in the system for any particular sequence of characters, so one can test #foo == #foo and get back true.
- A String representing the object's name. This can be convertd to a Symbol using asSymbol, so 'foo' asSymbol will return the (guaranteed unique) symbol #foo, generating it if it has to.
-- BEWARE - possibly old information ahead - check for refactorings before trying this --
Classes can be obtained by asking the sole instance of SystemDictionary, conveniently named Smalltalk, for the class named by a specified symbol. So to get the class for MyClass:
Smalltalk at: #MyClass
Smalltalk at: 'MyClass' asSymbol
You can then do whatever you wish with the class.
Does this help, or is it as clear as mud?
- Peter
More information about the Squeak-dev
mailing list
|