Is Dwemthy's Array possible in smalltalk?

Hans-Martin Mosner hmm at
Fri May 13 19:46:12 UTC 2005

Darren Hobbs wrote:
> There's a very interesting article here about metaprogramming in Ruby:
> The final section is titled Dwemthy's Array and links to the original
> code here:
> I've inlined the most interesting code from that page below. 
> In a nutshell what it does is dynamically add fields to subclasses of
> the Creature class.  The 'traits' line about halfway down says call the
> class method 'traits' passing a array of symbols.
> Creature.traits is a class method.  @traits is an instance variable I
> think, my Ruby isn't that great and the fact that it's being accessed
> from a class method is confusing me..
> My question is, is this kind of metaprogramming possible in Smalltalk?

Short answer: yes of course.
Smalltalk has all that's needed to create and modify classes in the runtime
(actually, the whole Smalltalk IDE does nothing else but that).
You can create instance-specific behaviors etc.

I won't go into the details of how it is being done.
Have a look at Russell Allen's page at
for some code.


More information about the Squeak-dev mailing list