In the version of Ruby i'm using, (1.8.6 - don't ask), the Hash class doesn't define the Hash#hash
method, which means that calling uniq
on an array of hashes doesn't test whether the content is the same - it tests whether the objects are the same (using the default base Object#hash method).
To get around this, I can use include?
, like so:
hashes = <a big list of hashes>
uniq_hashes = []
hashes.each do |hash|
unless uniq_hashes.include?(hash)
uniq_hashes << hash
end
end;uniq_hashes.size
Can anyone think of a way to condense this into a one-line method?