Hash suprise

From: Torsten Rer <torsten.rueger@...>
Date: 2002-10-09 07:48:46 UTC
List: ruby-core #534
Moi

I was trying to modify hash keys (strings) yesterday, and found to my 
surprise that they are frozen. Why ?

So when I
1 put a string key into a map then the key === the original
2 modify the original string, the key is not the same as the original 
anymore
3 I repeat this experiment with another class , and 2 changes to true, 
so the key is the the same as the modified object (as expected)

This difference in behaviour is in rb_hash_aset, where the type is 
checked for String and a copy made in that case.

I was quite surprised, is there a rationale ?

Thanks
    Torsten


In This Thread

Prev Next