Conundrum... tried Smalltalk allClasses
and TBehaviour
in Kernel-Traits
, among others, seems to be missing from the list. Interestingly enough it is a Trait
not a Class
...? there seem to be corresponding allTraits
and allBehaviors
.
Any others we should know about when trying to get everything? Or is there some other method to get everything?
您需要执行:
Smalltalk allClassesAndTraits.
Note: I thought that reflection was described in some Pharo book but I don't see it in any, so can't direct you for further reading. 🤔
You can always use reflection on Pharo objects, which might give you a bit more insight into what you are actually looking for.
Any class is also an object, an any object understands message allSubclasses
(or withAllSubclasses
) that will give you... the subclasses.
Object willAllSubclasses
Note that the above will give you also the "class-side" classes (which are metaclass instances for each class), because they are objects too; so
Smalltalk allClasses asSet =¹ (ProtoObject withAllSubclasses \ Class allSubclasses) asSet
"or"
Smalltalk allClasses asSet = (ProtoObject withAllSubclasses \ Metaclass allInstances) asSet
Trait
is a class, but TBehavior
is not; instead it is an instance of Trait
.
So you can say
Trait allSubclasses. "an OrderedCollection()"
Trait allInstances. "{... TBehavior. TClass. ...}"
¹ SMarkCompilerTargetClass
is some special snowflake.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.