[#1551] Hashes as keys — "Nathaniel Talbott" <nathaniel@...>

I was just playing around with Hash#hash and discovered that you can't use a

13 messages 2003/09/23

Re: Hashes as keys

From: matz@... (Yukihiro Matsumoto)
Date: 2003-09-24 15:57:21 UTC
List: ruby-core #1569
Hi,

In message "Hashes as keys"
    on 03/09/24, "Nathaniel Talbott" <nathaniel@talbott.ws> writes:

|I was just playing around with Hash#hash and discovered that you can't use a
|Hash as a key in a hash:
|
|  h = {{} => 'a'}
|  p h[{}]
|
|  => nil
|
|Is this intentional? Since hash overrides #==, I expected it to do the same
|with #hash, but it appears that it just uses Object#hash, which is different
|for every instance.

I believe you've understand now.  You *can* use hashes as keys, but
it's designed to be useless.

							matz.

In This Thread