Project

General

Profile

Bug #869

hashed hashes don't work in 1.8.6

Added by rogerdpack (Roger Pack) over 10 years ago. Updated over 8 years ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
[ruby-core:20530]

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

History

#1

Updated by matz (Yukihiro Matsumoto) over 10 years ago

  • 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

#2

Updated by rogerdpack (Roger Pack) over 10 years ago

=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

#3

Updated by rogerdpack (Roger Pack) over 10 years ago

=begin
Might be nice to fix that someday.
Cheers.
-=r
=end

Also available in: Atom PDF