[#1491] bug — Mathieu Bouchard <matju@...>
6 messages
2003/09/01
[#1492] non-blocking mode behavior (Re: bug)
— nobu.nokada@...
2003/09/01
Hi,
[#1512] New tests — Dave Thomas <Dave@...>
I was looking through the new test/ruby/* stuff just now, and notices
6 messages
2003/09/05
[#1533] GC disable / enable question — Torsten Rueger <torsten.rueger@...>
Moi,
7 messages
2003/09/17
[#1534] Re: GC disable / enable question
— nobu.nokada@...
2003/09/17
Hi,
[#1541] How to debug ? — Torsten Rueger <torsten.rueger@...>
Moi,
6 messages
2003/09/19
[#1542] Re: How to debug ?
— ts <decoux@...>
2003/09/19
>>>>> "T" == Torsten Rueger <torsten.rueger@hiit.fi> writes:
[#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
[#1552] Re: Hashes as keys
— Jim Freeze <jim@...>
2003/09/23
On Wednesday, 24 September 2003 at 6:21:33 +0900, Nathaniel Talbott wrote:
[#1556] ostruct.rb patch — "Nathaniel Talbott" <nathaniel@...>
I've been finding OpenStruct to be very useful lately, and then I discovered
9 messages
2003/09/24
[#1557] Re: ostruct.rb patch
— "NAKAMURA, Hiroshi" <nahi@...>
2003/09/24
Hi, Nathaniel,
Re: Hashes as keys
From:
"Nathaniel Talbott" <nathaniel@...>
Date:
2003-09-23 22:28:04 UTC
List:
ruby-core #1554
Jim Freeze [mailto:jim@freeze.org] wrote:
> irb
> irb(main):001:0> h={}
> => {}
> irb(main):002:0> hh = {:fred=>2}
> => {:fred=>2}
> irb(main):003:0> h[hh] = 3
> => 3
> irb(main):004:0> h
> => {{:fred=>2}=>3}
> irb(main):005:0> h[{}] = 4
> => 4
> irb(main):006:0> h
> => {{:fred=>2}=>3, {}=>4}
>
> You mean like that?
Sure, you can assign a Hash as a Hash key, but it's mostly useless. For
instance:
irb(main):001:0> h = {{} => 'a'}
=> {{}=>"a"}
irb(main):002:0> p h[{}]
nil
=> nil
The underlying question is, why do two Hashes with the same content have
different hash values?:
irb(main):001:0> h1 = {}
=> {}
irb(main):002:0> h2 = {}
=> {}
irb(main):003:0> h1 == h2
=> true
irb(main):004:0> [h1.hash, h2.hash]
=> [22880740, 22876600]
My guess is that Hash doesn't override Object#hash, but that of course
raises its own question :-)
Nathaniel
<:((><