"Singletons" package on SM

Stéphane Rollandin lecteur at zogotounga.net
Thu Dec 4 08:49:32 UTC 2003


 > I've just placed a 15 minute hack on SM that might be useful to some 
people.  It allows for
 > instance-specific behavior, or what's nicely termed "singleton methods" 
in Ruby.  I'm interested
 > in comments.


I'm very interested in this idea (primarily in order to easily associate 
arbitrary comments to individual morphs)


I tried this in a workspace:

	| uh |

	Smalltalk recreateSpecialObjectsArray.
	uh _ Morph new.
	uh becomeSingleton.
	uh delegate: #extent to: World.
	uh extent.

... and it worked fine (returned the World extent)


I also try those two:

	| uh |

	Smalltalk recreateSpecialObjectsArray.
	uh _ #().
	uh becomeSingleton.
	uh delegate: #size to: #(1 2 3).
	uh size.

and:

	| uh |

	Smalltalk recreateSpecialObjectsArray.
	uh _ 'abcde'.
	uh becomeSingleton.
	uh to: #size run: [18].
	uh size.

... both of them made Squeak (3.6-5424, 3.6.2 VM) hang badly (no answer to 
Alt-.)

It would be nice to have an error sent when the singleton methods can not 
be implemented. BTW, what are the rules allowing to know if a given class 
will support that ?


regards,

Stef




More information about the Squeak-dev mailing list