![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Next, you make use of isWeight
in a new definition of the +
method, defined previously in Segment 556. If the argument
is a Weight
instance, then activity proceeds as before. If the
argument is not a Weight
instance, then the
error:
message is sent, with an argument that is used in
the error display:
Weight method definition instance + aWeight aWeight isWeight ifTrue: [^ (self magnitude + aWeight magnitude) gm] ifFalse: [self error: 'Oops--Cannot send + to ' , self printString , ' with ' , aWeight printString , ' as an argument']