From: Hal Fulton Date: 2006-07-26T10:18:24+09:00 Subject: Re: Hash order bug? William James wrote: > No. What language has ordered hashes? > > When you say > a = {:gr => false, :und => false, :det => true, :sta => false, :inv > => false} > you are saying that you want to access the values in this fashion: > a[:und] > So the order in which they are stored is irrelevant. > If you want to access them this way > a[1] > then you set them up like this > [ false, false, true, false, false ] > > If you want to get a sequence of values in a certain order: > a.values_at( :und, :det, :sta ) Your point is well taken. David Alan Black also argues eloquently against the concept of an ordered hash. But to me there is psychological weight in seeing a literal of this form: {a=>b, c=>d, e=>f} There is in fact a syntactic order (which turns out to be meaningless internally). > If you want to have your cake and eat it too, you could > use an association list: > > >>>as = [[:foo,22], [:bar,33], [:baz,44]] > > => [[:foo, 22], [:bar, 33], [:baz, 44]] [snip] That works fine, but I dislike the ugly syntax. Hal