From: Trans Date: 2005-12-10T02:02:36+09:00 Subject: Re: ordered/sorted hash Okay, I have preliminary implementation of Dictionary class with built-in ordering. Its important to note that the implementation isn't as efficient as sorting externally b/c the class sorts the pairs *every time* #each is called (if order_by is set). There are ways to improve the efficiency, but that's a task for another day. The basic way to do it: d = Dictionary.new.order_by{ |k,v| k } This creates a dictionary orderd by the key. The block allows you to define almost any order mechisim you like. Since alphanumeric key order is likely the most common (after the default of insertion order) I created a special constructor method just for it: d = Dictionary.alpha This does the exact same thing is the last example. The only thing I'm not so sure about is the name of this method. Is this good or would something else be better? BTW, Ara, you inspired me: d = Dictionary.auto will do the same as OrderedAutoHash::new. Thanks for that idea. Of course, I have the same question about my choice of method name here too. T.