From: Tim Hunter Date: 2002-11-23T09:39:22+09:00 Subject: [FAQ] Defining <=> At Gavin's request here is a summary of my question and the answers I received. Q: I've defined a class whose objects may be ordered. What should my <=> method do when the "other" argument is not in the same class? A. Raise a TypeError exception. The <=> method in most of Ruby's built-in classes will raise a TypeError exception if "other" can't be coerced into the same class. If you want your class to include the other comparision operators such as ==, <=, =>, etc., consider mixing in the Comparable module. This module implements these other comparison operators by calling your <=> method. For example, class TestClass include Comparable def <=>(other) unless other.kind_of? self.class raise TypeError, "#{other.class} can't be coerced into #{self.class}" end # do whatever it takes to compare self <=> other end # other methods end