From: Dave Date: 2002-01-27T05:53:22+09:00 Subject: Why isn't Range Comparable? Maybe I'm missing something, or maybe this has been discussed already and I just haven't found it yet in the archives.... If a Range is an ordered set, which depends on it's members having '<=>' and succ() methods, then why is there no Range#<=>, so to speak? This simple experiment seems to work fine with a Range of Fixnums, but I haven't tried other object types yet: irb(main):016:0* class Range irb(main):017:1> def <=>(other) irb(main):018:2> return 0 if self.member?(other) irb(main):019:2> return -1 if other < self.begin irb(main):020:2> return 1 if other > self.end irb(main):021:2> raise "Bogus!" irb(main):022:2> end irb(main):023:1> end irb(main):025:0> (1..10) <=> 11 1 irb(main):026:0> (1..10) <=> 0 -1 irb(main):027:0> (1..10) <=> 1 0 I'd find this useful in deciding between exception messages, for example.