▲ | wild_egg a day ago | |||||||
In Smalltalk those methods don't return `true`. They take a block and evaluate it if the boolean receiving the message
EDIT: to clarify what's happening there, `>` is a message sent to `a` that will result in a boolean. The True class and False class both understand the ifTrue: message and `True>>ifTrue:` executes the block whereas `False>>ifTrue:` just throws it away.There's no `if` keyword in the language. Control flow is done purely through polymorphism. | ||||||||
▲ | chao- a day ago | parent | next [-] | |||||||
I apologize for my lack of Smalltalk knowledge. As you can imagine, you can do similar in Ruby by defining ifTrue to accept a block, even adding ifTrue on other all objects and defining something similar:
If ck45's core complaint was that this is not baked into the language, I will agree that it is less convenient for lack of a default. | ||||||||
▲ | oezi a day ago | parent | prev [-] | |||||||
Certainly possible: add ifTrue as a method to TrueClass and FalseClass. It just isn't very fast. | ||||||||
|