# Making Array#uniq work

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

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 24, 2006, 12:37pm UTC](https://www.ruby-forum.com/t/making-array-uniq-work/96518/1 "2006-01-24T12:37:11Z")

</div>

OK, according to the Pickaxe 2nd. Edition, Array#uniq judges uniqueness  
based on eql?. Somehow this doesn’t seem to work for me :).  
Following code returns the Array with two members instead of the one I  
would wish for. Any pointers? I’m running 1.8.2

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  
end

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

[http://www.braveworld.net/riva](http://www.braveworld.net/riva)
