From: Robert Klemme Date: 2007-05-18T17:40:20+09:00 Subject: Re: questions about reimplementing core classes On 17.05.2007 22:08, Ball, Donald A Jr (Library) wrote: > I had reason to need a sorted map recently and thought it might be a > useful exercise to write it as a complete drop-in replacement for Hash, > backed by a sorted array. An hour or so later: > > http://pastie.caboo.se/62458 > > A few questions arose while I was writing which I'd like to pose to > y'all: > > 1. I'm storing entries as struct objects, the class definition for which > is stored in a class constant. Good or bad practice? I note that I get a > constant redefinition warning when I reload the class. I could easily > enough use a two element array, but thought a struct would be more > efficient and be more clear. > > 2. I'm extending Hash, not because I need to, but so that I could pass > kind_of? tests if necessary. Good or bad practice? > > 3. I had vaguely thought that the default freeze implementation would > freeze all instance variables, but it does not. Is this a good way to > implement freeze? (with the exception of the incorrect return value?) > > 4. Should I be checking block_given? in delete_if, et. al.? Should I be > explicitly declaring a &blk argument? > > Thanks for any tips. How about using http://raa.ruby-lang.org/project/ruby-rbtree/ ? Btw, this is one of two hits for http://raa.ruby-lang.org/search.rhtml?search=sorted%20hash :-) Kind regards robert