I have a hash that maps an array of integers to an integer. For some reason the hash has one key mapped to multiple values like:
{[1,2]=>3, [1,2]=> 4}
How can I prevent this from happening? Running
for key, value in map
puts key.inspect + "=>" + value.inspect + ":" + key.hash.inspect
end
gives me
[1, 2]=>11:11
[0, 4, 6, 8, 9]=>10:253
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]=>15:11189
[0, 3, 4, 6, 7, 8, 9]=>13:981
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]=>14:11189
[0, 1, 2, 4, 5, 6, 7, 8, 9]=>12:4661
I can think of two cases. The first has the obscure
compare_by_identityswitched on. Don’t know what to do about it. Don’t switch it on? Copy everything to a normal hash?The second case is more plausible: the key gets changed after being put in the hash.
That’s easy to remedy (but also easy to forget):