Hi,
In message "[ruby-talk:8046] Re: Basic hash question"
on 00/12/25, Dave Thomas <Dave / PragmaticProgrammer.com> writes:
|
|I understand that, Guy. But we're not talking underlying
|implementation here (because we hope it's transparent to the
|user). The difference between strings and other objects wrt. hashes is
|that the string (object) is copied when it is inserted in to the hash,
|while other objects aren't:
|That's a significant user-level difference.
Yes. And this is my intension. The reference clearly states the
fact:
The hash value for the key value is calculated using method Kernel#hash.
Since the hash value of the key should not be changed, instances of the
classes like Array, Hash, etc. are not suited for the key. When the string
used as the key, hash table copies and freeze it and use copied string as
the key string. Attempt to Modify the freezed key strings raises an
exception.
But subclassing problem is another story which should be fixed.
matz.