"David A. Black" <dblack / wobblini.net> schrieb im Newsbeitrag news:Pine.LNX.4.44.0412030519240.28725-100000 / wobblini... > Hi -- > > On Fri, 3 Dec 2004, Robert Klemme wrote: > > > Hm, I'd prefer the "natural" order of key elements, i.e. the order defined > > by <=>. > > The problem is, though, that keys can be anything, including things > that don't respond to <=> or that can't be meaningfully compared with > other keys. But that's okay: you'll get bitten by an exception if you insert such keys. It will work perfectly for the most common key types (I guess these are String and maybe Fixnum). If you want such keys then you can easily define your own ordering with the lambda you provide. class Foo attr_accessor :bar end oh = OrderedHash( lambda {|foo1,foo2| foo1.bar.size <=> foo2.bar.size} ) oh[Foo.new]="bar" .... Kind regards robert