From: Michael Neumann Date: 2004-12-02T22:23:49+09:00 Subject: Re: ordered hash ? itsme213 wrote: > Is there a pure-ruby ordered hash? I'm looking for something that will > preserve the order in which key/value pairs were entered. The one on RAA is > buggy http://raa.ruby-lang.org/project/orderedhash/ > > Will 2.0 come with a good ordered hash? This works fine for me: class OrderedHash < Hash def initialize @order_of_keys = [] super end def []=(key, value) @order_of_keys.delete(key) if has_key?(key) @order_of_keys << key super end def each @order_of_keys.each do |key| yield key, self[key] end end end Regards, Michael