From: Darshan Ishaya Date: 2006-11-23T15:17:31+09:00 Subject: Re: Compare Array Values? I think it does! I think hash() is the magic method that I was looking for originally. I considered object_id(), but objects that are eql? can have different object_id's, so it was a no-go. hash() seems to be the magic one. I think you get the award. Darshan Farrel Lifson wrote: > On 23/11/06, Darshan.Ishaya wrote: >> Well, I'm new to Ruby, but it was an interesting question so I gave it >> a stab. My first idea was >> >> a.sort == b.sort >> >> which works if all the elements of an array of of the same class. But >> if you mix objects of different class (like you example with Fixnums >> and a String), sort() craps out on it. You can pass a block to sort, >> but I couldn't think of a good way to use that to our advantage. So I >> resorted to more of a brute force method: > > Would this work? > a.sort_by{|n| n.hash} == b.sort_by {|n|n.hash} > > Farrel > >