Bug #869
closed
hashed hashes don't work in 1.8.6
Added by rogerdpack (Roger Pack) over 15 years ago.
Updated about 13 years ago.
Description
=begin
Appears that in 186 [not 1.8.7, nor 1.9]
a = {}
a[{:a => 3, :b => 4}] = 5
=> 5
a[{:a => 3, :b => 4}]
=> nil
Thanks for help.
ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mingw32]
-=R
=end
- Status changed from Open to Rejected
=begin
Hashes as hash keys are compared by equivalence, i.e. only the same object treated as same keys. It's a spec.
=end
=begin
Ahh--I see. Different hashes with the same key/values don't necessarily have the same order, hence not necessarily the same #hash value, so the fact that it works in 1.8.7/1.9:
$ irb
RUBY_VERSION
=> "1.8.7"
a = {}
=> {}
a[{:a => 3, :b => 4}] = 5
=> 5
a[{:a => 3, :b => 4}]
=> 5
exit
$ ruby_1_9_svn_installed/bin/irb
a = {}
=> {}
a[{:a => 3, :b => 4}] = 5
=> 5
a[{:a => 3, :b => 4}]
=> 5
Is most likely a freak thing [except in 1.9, since order matters, it should hash the same if they're created the same way [?]].
http://blog.playlouder.com/2008/05/07/an-interesting-ruby-hash-semantics-gotcha/ Explains it better.
Thank you.
-=R
=end
=begin
Might be nice to fix that someday.
Cheers.
-=r
=end
Also available in: Atom
PDF
Like0
Like0Like0Like0