From: Dave Thomas Date: 2001-03-06T23:10:50+09:00 Subject: [ruby-talk:12135] Re: hash.invert loses data if equal values exist - is this the right behaviour? Tammo Freese writes: > By inverting a hash that has same values, I expected to see an Exception. > Curious which it would be, I tested it and found a surprising result: > > D:\software>ruby -ve 'p [hash = Hash[1, 3, 2, 3], hash.invert]' > ruby 1.6.2 (2000-12-18) [i386-cygwin] > [{1=>3, 2=>3}, {3=>2}] > > No exception. Is this correct? Any reason why there should be an exception? h = { 1 => 2 } # => {1=>2} h[1] = 3 # => 3 h # => {1=>3} It isn't exceptional to overwrite a value in a hash with another. Dave