문제

I have tried and failed to find a way in Pharo to find if a specific class instance has specific class as super class. By super class I am not referring only on the class that is a subclass of, but also all other classes that are up its inheritance line.

I thought that there would be a message in Object >> isSubclassOf: but alas i cant located such message

도움이 되었습니까?

해결책

I'm not clearly sure what do you want to find, but if you want to see if anObject is and instance of aClass or it's superclasses, you can use:

anObject isKindOf: aClass

If you want to see if anObject (class) inherits from aClass, then you use:

anObject inheritsFrom: aClass

다른 팁

Only a class can be the subclass of another class. Thus you must first get the class of your object:

String inheritsFrom: Collection "prints: true"
'Pharo is cool' class inheritsFrom: Collection "prints: true"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top