Understanding the Implementation of ifTrue:ifFalse:

Damien Cassou, St├ęphane Ducasse and Luc Fabresse http://stephane.ducasse.free.fr

Yes ifTrue:ifFalse: is a message!

Weather isRaining
    ifTrue: [ self takeMyUmbrella ]
    ifFalse: [ self takeMySunglasses ]

Exercise

   false ifTrue: [ 3 ] ifFalse: [ 5 ]
   -> 5

   true ifTrue: [ 3 ] ifFalse: [ 5 ]
   -> 3

Implementing ifTrue:ifFalse:

Implementation of ifTrue:ifFalse:

Let the receiver decide!

True >> ifTrue: aTrueBlock ifFalse: aFalseBlock
   ^ aTrueBlock value
False >> ifTrue: aTrueBlock ifFalse: aFalseBlock
   ^ aFalseBlock value

Implementation of ifTrue:ifFalse:

Conclusion

/