Category:Smalltalk: Difference between revisions

Line 403:
Now, we can send this message to a boolean, and pass the code to be executed conditionally as a lambda block:
<lang smalltalk>(a > 0) ifYouAreTrueThenDo:[ 'positive' printCR ] ifNotThenDo:[ 'negative' printCR ]</lang>
actually, because these two return the value of the block ethylthey evaluated, it can also be used for its value (in C, the ternary if expression), as in:
<lang smalltalk>( (a > 0) ifYouAreTrueThenDo:['positive'] ifNotThenDo:['negative'] ) printCR</lang>
Finally, by adding a self-returning "value" to the Object class, we can also write:
Anonymous user