Squeak
  links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
How can I show the number of all the instances of all classes in a category?
Last updated at 4:15 am UTC on 28 October 2003

Answer:

| totalNumberOfAllInstances |
Transcript clear.
totalNumberOfAllInstances _ (SystemOrganization listAtCategoryNamed: 'MyCategory-Subcategory')
	inject: 0
	into:
		[:sum :each | | numberOfCurrentClassInstances |
		numberOfCurrentClassInstances _ (Smalltalk classNamed: each) allInstances size.
		Transcript
			show: each asString , ': ';
			show: numberOfCurrentClassInstances;
			cr.
		sum _ sum + numberOfCurrentClassInstances].
Transcript cr; show: 'Total: ' , totalNumberOfAllInstances asString