[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

test[m8n] 10 class hierarchy

--Object must be root class
if (smalltalk.Object["$superclass"]~=nil) then error("Object must be root") end
if (smalltalk.Object["$klass"]["$superclass"]~=smalltalk.Class) then error("Object class must be subclass of Class") end

--Point is subclass of Object
if (smalltalk.Point["$superclass"]~=smalltalk.Object) then error("Expected that Point subclass of Object") end

--Collect Object subclasses
local subclasses = smalltalk:subclasses(smalltalk.Object); print("Object has "..#subclasses.." direct subclases, an"..subclasses["$klass"]["$className"]);for i,v in pairs(subclasses) do print(i,v["$className"]) end

--Enumerate all class hierarchy from Object
smalltalk:allSubclassesDo(smalltalk.Object,function(cls) print(cls["$className"]) end)