Skip to content

Instantly share code, notes, and snippets.



Last active Jun 13, 2019
What would you like to do?
package metaobjectTest
Annotation 'countNew' should be attached to a 'init' or 'init:' method.
It increments a global variable each time the method is called. When
attached to all 'init' or 'init:' methods of a prototype, it counts
how many objects were created. This number is put in a table called
"CountNew" whose key is the prototype name (with the package). See
the example below.
object CountNew
func init {
func init: Int n { }
func run {
assert numberOfObjectsCreated == 0;
var cn1 = CountNew();
assert numberOfObjectsCreated == 1;
var cn2 = CountNew new: 2;
assert numberOfObjectsCreated == 2;
var cn3 = CountNew new;
assert numberOfObjectsCreated == 3;
func numberOfObjectsCreated -> Int {
cast table = (System globalTable get: "CountNew") {
type table get: "metaobjectTest.CountNew"
case Int count {
return count
return 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment