links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
How to get the class object if the name is given as a string
Last updated at 12:56 pm UTC on 20 December 2005
Hilaire Fernandes on December 14, 2005 I have a class name under a string form. Let's say "MyClass", I want to
do a class method call with it, how I can I do it ?

Stijn Timbermont
 Compiler evaluate: 'MyClass methodName: arg' 
won't work, because the Compiler will not be able to see arg.
 (Smalltalk classNamed: clsName) methodName: arg. 
is the best way I think, clsName may be a string or a symbol, it can also be 'MyClass class' (or #'MyClass
class'). Even better is
 self class environment: classNamed: clsName.
that way your code will also work in a partitioned system (where not all classes are in the Smalltalk global)