Beginner smalltalk question: Open Classes and Smalltalk

Colin Putney cputney at wiresong.ca
Mon Jan 16 03:27:27 UTC 2006


On Jan 15, 2006, at 9:17 PM, Rich wrote:

> The Ruby language supports the concept of "Open Classs" or that at
> run-time a class can have methods added to it, or in general have it's
> definition modified.  As I understand it, the idea for this originally
> came from Smalltalk.  If so, how would I go about adding methods (in
> the workspace, for example, just to test things out)?  Thanks alot.

The short answer would be evaluate something like this in workspace:

Object compile: 'one ^ 1'.


The longer answer is that adding a method at runtime is the only way  
to create methods at all. When you accept a method in the browser it  
does something very similar to the message send above, sending a  
message to the class to compile a method. In Smalltalk, run time is  
all the time.

Colin



More information about the Squeak-dev mailing list