From: cilibrar@... (Rudi Cilibrasi) Date: 2002-10-25T20:44:40+09:00 Subject: How come true, false don't support <=> (comparison) operator? I am wondering if there is a good reason why Ruby does not by default support, for instance, true <=> false (should be +1 or -1) or even false <=> false (should be 0) I have been surprised at having to make my own versions of these functions for use in an Array of boolean values. Some people suggest that I would be better off using integers and bitmasks, but the Array has many methods that I need to use; for example, the <=> operator as applied to booleans: a = Array.new(10, true) b = Array.new(10, false) It would be convenient if I could compare the two bitstrings lexicographically. a <=> b Another common thing I find myself needing is to sort these, like: a.sort! I have used the following code to make these operations work: class TrueClass def to_i() 1 end def <=>(b) to_i <=> b.to_i end end class FalseClass def to_i() 0 end def <=>(b) to_i <=> b.to_i end end Would anything break if this were made a part of the standard package? In thinking about possibilities for future versions of Ruby, perhaps it would make sense to have TrueClass and FalseClass both derive from a common base class, say, BooleanClass. I would enjoy hearing your thoughts as a followup in this forum, Rudi Cilibrasi