我有一个问题,我对它完全陌生,所以我问的是基础知识。我创建了一个类
Object subclass: #Course
instanceVariableNames: 'id name day time isTwoHoursLong'
classVariableNames: ''
poolDictionaries: ''
category: 'Kernel-Objects'
它实现了以下方法:
isTwoHoursLong: aBoolean
(aBoolean isMemberOf: Boolean)
ifFalse: [self error: 'invalid input value']
ifTrue: [isTwoHoursLong:=aBoolean.].
aBoolean 必须为 true 或 false(Boolean 的一个实例)。 现在我尝试使用以下方法:
|c1|
c1:=Course new.
c1 isTwoHoursLong:true.
但出于某种原因,我陷入了发送错误的 ifFalse 选项。 有人可以帮忙清理一下吗?
请您参考如下方法:
尝试使用 isKindOf:
而不是 isMemberOf:
。
True
和 False
是 Boolean
的子类,isKindOf:
测试参数是类还是父类(super class)接收者。
但我可能会完全忽略这种手动类型检查。