On Fri, 9 Dec 2005, Trans wrote: >>> is there anywhere a class that does soemthing >>> akin to java.util.SortedMap? that is sorting >>> and iterating over the hash in the order of its >>> keys. >>> >>> i had a look into facets dictionary but that does >>> only preserve the ordering of insertion which >>> is not what i want. >>> >>> any other suggestions? >>> >>> ciao robertj >> >> harp:~ > cat a.rb >> require "alib" >> include ALib >> >> oh = OrderedHash::new >> oh["first"] = 42 >> oh["second"] = "forty-two" >> >> puts "---" >> oh.each{|k,v| puts "#{ k } : #{ v }"} >> >> harp:~ > ruby a.rb >> --- >> first : 42 >> second : forty-two > > Insertion order? yup. this is my favourite usage: harp:~ > cat a.rb require "alib" config = ALib::OrderedAutoHash::new config["db"]["port"] = 5432 config["db"]["host"] = "localhost" config["db"]["host"] = "postgres" config["site"]["uri"] = "http://codeforpeople.com" y config harp:~ > ruby a.rb --- db: port: 5432 host: postgres site: uri: http://codeforpeople.com ahhh. -a -- =============================================================================== | ara [dot] t [dot] howard [at] noaa [dot] gov | all happiness comes from the desire for others to be happy. all misery | comes from the desire for oneself to be happy. | -- bodhicaryavatara ===============================================================================