From: Hal Fulton Date: 2006-07-26T09:36:17+09:00 Subject: Re: Hash order bug? Berger, Daniel wrote: > > > No, it's just the way hashes behave. Note that there are ordered hash > implementations on the RAA: > > http://raa.ruby-lang.org/project/orderedhash/ > > You can also use a Struct to get roughly the same effect. In case anyone tries to refer me to these, I'll point out that there are *three* reasons I like a hash. 1. It indexes on an arbitrary value, not on an integer like an array. 2. It consists of explicit pairings of key and value. 3. There is a convenient sybtax for literals: {a=>b, c=>d, e=>f} Note that there are *no* ordered hash solutions that preserve the third criterion. Most would require me to do something like: oh = OrdHash.new(a,b, c,d, e,f) or oh = OrdHash.new([a,b], [c,d], [e,f]) or something just as bad. Don't underestimate the importance of a convenient notation! What if arrays in Ruby were like arrays in C? In C, you can specify an array literal (barely) when you declare it; that's about it. Hal