From: Michael H Buselli Date: 2004-09-09T04:13:48+09:00 Subject: Re: OK... :) question about hash and array literals On Mon, 06 Sep 2004 13:10:12 +0900, Ara.T.Howard@noaa.gov wrote: > On Mon, 6 Sep 2004, Yukihiro Matsumoto wrote: > > > Hmm, I thought hash order would be ignored always for compares. > > Optional use of order is an interesting idea, although I want better > > looking API than > > > > | {1=>2, 3=>4}.ordered != {3=>4, 1=>2}.ordered > > this is a GREAT idea! i've always thought that there is no reason hashes > could not simply remember the order of inserts and use it. as far as > comparisons i would agree they should not be ordered in general, perhaps > > hash.identical other > > or something that did depend on order. one of the coolest things about > ordered hashes would be their use with yaml! i use yaml configs and the lack > of hash ordering is a constant pain in my side. how difficult do you think i >-t > would be to add order memory for hash insert operations and to use it for > each/map, etc.? Sounds like a new data type to me. I frequently find myself doing things like this: @some_data_by_index = Hash.new @some_data_order = Array.new and then I manage the two variables together for any insertion I make into the data: @some_data_by_index[value.key] = value @some_data_order.push value So what if there was an ArrayAndHash? @some_data = ArrayAndHash.new(:key) @some_data.push value Such a thing would need some semantics of both an Array and a Hash, and I don't feel like figuring out what they should look like right now. Maybe next time I need such a thing I'll think about it more. Similar things have been discussed on the list before, but I don't know if anything became of them. T\_/T\_/T Michael H Buselli "If you give a man a phish, he has a stolen credit card for a day. If you teach a man to phish, he will eat three square meals daily for a lifetime; perhaps served from behind bars, but he will not go hungry."