测试 class 的实例
testing for instance of a class
我有一个关于 squeak 的问题,我对它完全陌生,所以我问的是基础知识。我创建了一个 class
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
的子class 并且 isKindOf:
测试参数是 class 还是超class接收器。
但我可能会完全忽略此手动类型检查。
我有一个关于 squeak 的问题,我对它完全陌生,所以我问的是基础知识。我创建了一个 class
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
的子class 并且 isKindOf:
测试参数是 class 还是超class接收器。
但我可能会完全忽略此手动类型检查。