Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Array#uniq - Comparison doesn't use 'eql?' and 'hash'
WoNáDo
2/20/2007 7:16:00 AM
I am confused about "Array#uniq". In
http://groups.google.com/group/comp.lang.ruby/msg/e57b80...
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
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Array#uniq - Comparison doesn't use 'eql?' and 'hash'
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password