On Jun 20, 2006, at 9:26 AM, Kroeger, Simon (ext) wrote:

>> From: James Edward Gray II [mailto:james / grayproductions.net]
>> Sent: Tuesday, June 20, 2006 4:17 PM
>>
>> Would someone please explain this behavior to me?
>>
>>    a = [ { :foo => :bar }, { :foo => :bar } ]
>>
>>    p a            #=> [{:foo=>:bar}, {:foo=>:bar}]
>>    p a[0] == a[1] #=> true
>>    # why does this next call do nothing?
>>    p a.uniq       #=> [{:foo=>:bar}, {:foo=>:bar}]
>>
>>    # inefficient work-around
>>    p a.inject([]) { |cp, e| cp.include?(e) ? cp : cp << e } #=>
>> [{:foo=>:bar}]
>>
>> James Edward Gray II
>
> a = [ { :foo => :bar }, { :foo => :bar } ]
>
> class Hash
>     def hash
>         self.to_a.sort.hash
>     end
>
>     def eql? other
>         size == other.size && keys.all?{|k| self[k] == other[k]}
>     end
> end
>
> p a.uniq #=> [{:foo=>:bar}]

So which one is uniq() really using?  eql?()?

James Edward Gray II