Mutable Hash Keys

Caveat. Mutable hash keys in ruby obviously behave different than you would expect:

>> foo = [1, 2, 3]
[1, 2, 3]
>> bar = {foo => 42}
{[1, 2, 3]=>42}
>> foo << 4
[1, 2, 3, 4]
>> bar[foo]
nil

Update: there is Hash#rehash.

Leave a Reply

cogitations driven by wordpress