# Hash again

**URL:** <https://www.ruby-forum.com/t/hash-again/66303>\
**Category:** Ruby\
**Created:** [August 24, 2006, 5:42pm UTC](https://www.ruby-forum.com/t/hash-again/66303 "2006-08-24T17:42:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![flatekmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e8c25b/32.png) [@flatekmonkey](https://www.ruby-forum.com/u/flatekmonkey)\
**Post date:** [August 24, 2006, 5:42pm UTC](https://www.ruby-forum.com/t/hash-again/66303/1 "2006-08-24T17:42:23Z")

</div>

Following suit with the main trend, talking Hashes 😉

I was just thinking about the potential impact on syntax  
Right now  
{:a =\> 1, :a =\> 2}  
returns  
{:a =\> 2}  
in my irb

is this defined right now?  
And how ought that be handeled in a HistHash?

My personal feelings are that a duplicate hash keys in a hash literal  
should  
raise an Exception for any kind of Hash.

## Cheers Robert

Deux choses sont infinies : l’univers et la bÃªtise humaine ; en ce qui  
concerne l’univers, je n’en ai pas acquis la certitude absolue.

- Albert Einstein

---

<div class="post-metadata">

**Author:** ![flatekmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e8c25b/32.png) [@flatekmonkey](https://www.ruby-forum.com/u/flatekmonkey)\
**Post date:** [August 24, 2006, 11:23pm UTC](https://www.ruby-forum.com/t/hash-again/66303/2 "2006-08-24T23:23:19Z")

</div>

Robert D. wrote:

> And how ought that be handeled in a HistHash?
> 
> My personal feelings are that a duplicate hash keys in a hash literal  
> should  
> raise an Exception for any kind of Hash.

The literal probably “compiles” to something like  
foo = Hash.new  
foo[:a] = 1  
foo[:a] = 2

You might want to put that through irb while tracing the interpreter.  
So, the latest goes, and it’s probably fine enough, considering there’s  
only one kind of Hash literal in Ruby. It’s probably also faster since  
parsing the whole literal ahead-of-time to be able to check for  
duplicate keys would be messy. And imperfect, since the keys in the hash  
could be results of method calls, so you could only really check for  
duplicate literal keys. And if you did, then someone would expect there  
not to be duplicate keys ever in a HistHash (where I presume the result  
of adding a new value to a key results in something else than replacing  
the old value - I’m not familiar with the data structure) constructed  
with a literal, and shoot himself in the foot sooner or later.

David V.
