From: Paul Brannan Date: 2004-06-18T23:49:56+09:00 Subject: Re: How to make generic #== method? On Fri, Jun 18, 2004 at 10:15:44AM +0900, Joel VanderWerf wrote: > One way I've done it is this: > > module ContentEquality > def hash > content.hash > end > > def eql?(other) > content.eql? other.content > end > > def ==(other) > # self.class == other.class and # optional > content == other.content > end > end I like this, and since content is ordered, it's possible to write this too: module ContentEquality def <=>(other) content.each_with_index do |member, idx| result = member <=> other.content[idx] return result if result != 0 end return 0 end include Comparable end The only thing I don't like is that content doesn't carry any information about what it holds, so it's entirely possible to inadvertently compare apples and oranges. Paul