Skip to content

Instantly share code, notes, and snippets.

@joseoliv joseoliv/CountNew.cyan
Last active Jun 13, 2019

Embed
What would you like to do?
countNew
package metaobjectTest
@doc{*
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
@countNew
func init {
}
@countNew
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
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.