# Array#uniq - Comparison doesn't use 'eql?' and 'hash'

**URL:** <https://www.ruby-forum.com/t/array-uniq-comparison-doesnt-use-eql-and-hash/86153>\
**Category:** Ruby\
**Created:** [February 20, 2007, 8:20am UTC](https://www.ruby-forum.com/t/array-uniq-comparison-doesnt-use-eql-and-hash/86153 "2007-02-20T08:20:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wonado](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/919ad9/32.png) [@wonado](https://www.ruby-forum.com/u/wonado)\
**Post date:** [February 20, 2007, 8:20am UTC](https://www.ruby-forum.com/t/array-uniq-comparison-doesnt-use-eql-and-hash/86153/1 "2007-02-20T08:20:45Z")

</div>

I am confused about “Array#uniq”. In  
[http://groups.google.com/group/comp.lang.ruby/msg/e57b80fbcd61aaab](http://groups.google.com/group/comp.lang.ruby/msg/e57b80fbcd61aaab) it is  
described, that one has to redefine “eql?” and “hash”, if one needs an  
own  
“Array#uniq” interpretation.

I made tests with the result, that neither “eql?” nor “hash” is called.  
What  
went wrong here?

> > > > > code \>\>\>\>\>

class String  
alias :org\_hash :hash  
alias :org\_eql? :eql?  
def hash  
puts ‘String#hash called’  
self.hash  
end  
def eql?(other)  
puts ‘String#eql? called’  
self.eql?(other)  
end  
end

puts ‘Start of test’  
a = [‘a’, ‘b’, ‘a’, ‘c’, ‘b’]  
b = a.uniq  
p b  
puts ‘End of test’

> > > > > Output \>\>\>\>\>

Start of test  
[“a”, “b”, “c”]  
End of test

> > > > > EoE \>\>\>\>\>

Wolfgang Nádasi-Donner
