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.
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.