Re: Smalltalk's favorite Boolean method


#1

Recently, Ruby “got me” and I was wondering how the
famous ifTrue:ifFalse: could be added to the System.

1 = 2
ifTrue:
[Transcript show: “true!” ]
ifFalse:
[Transcript show: “false!”]
[…]

What about:

def true.ifTrue
yield; self
end

def true.ifFalse
self
end

def false.ifTrue
self
end

def false.ifFalse
yield; self
end

(1==2).
ifTrue {p “true!”}.
ifFalse {p “false!”}

(1!=2).
ifTrue {p “true!”}.
ifFalse {p “false!”}

But note that in ruby not only true is ‘true’
but every object other than nil or false.

cheers

Simon