Check if an object is an instance of a given class or of a subclass of it

Uko picture Uko · Dec 8, 2012 · Viewed 7.2k times · Source

Is there an easy way to do this in Smalltalk? I'm 80% sure that there is some method but can't find it anywhere.

I know that I can use

(instance class = SomeClass) ifTrue:

And I know that I can use superclass etc... but I hope that there is something built in :)

Answer

aka.nice picture aka.nice · Dec 8, 2012

To test whether anObject is instance of aClass:

(anObject isMemberOf: aClass)

To test whether it is an instance of aClass or one of it subclasses:

(anObject isKindOf: aClass)