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 ?
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)