Smalltalk's favorite Boolean method

What about:

···

-----Original Message-----
From: list-bounce@example.com
[mailto:list-bounce@example.com] On Behalf Of Ernest Micklei
Sent: Tuesday, April 11, 2006 3:13 PM
To: ruby-talk ML
Subject: Smalltalk's favorite Boolean method

Hi,

For a long time I have been programming Smalltalk.
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!"]
[...]

----------------------------------
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