# Re: Making Array#uniq work

**URL:** <https://www.ruby-forum.com/t/re-making-array-uniq-work/53061>\
**Category:** Ruby\
**Created:** [January 24, 2006, 1:04pm UTC](https://www.ruby-forum.com/t/re-making-array-uniq-work/53061 "2006-01-24T13:04:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![KroegerS\_Simon\_Sext](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/57b2e6/32.png) [@KroegerS\_Simon\_Sext](https://www.ruby-forum.com/u/KroegerS_Simon_Sext)\
**Post date:** [January 24, 2006, 1:04pm UTC](https://www.ruby-forum.com/t/re-making-array-uniq-work/53061/1 "2006-01-24T13:04:34Z")

</div>

> the one I  
> would wish for. Any pointers? I’m running 1.8.2

Hi,

you have to define a ‘hash’ method because Array uses a Hash to remove  
the duplicates.

## e.g.:

class A  
attr\_accessor :a,:b  
def initialize a  
@a=a  
@b=Array.new  
end  
def \<\< item  
@b\<\<item  
end

def eql? other  
return true if @a==other.a && @b==other.b  
end

def == other  
return eql?(other)  
end

def hash  
a.hash \* b.hash  
end  
end

## o1=A.new(“a”) o2=A.new(“a”) o1\<\<“o” o2\<\<“o” puts o1==o2 puts o1.eql?(o2) p [o1,o2].uniq

cheers

Simon
