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:
A few questions arose while I was writing which I’d like to pose to
y’all:
-
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. -
I’m extending Hash, not because I need to, but so that I could pass
kind_of? tests if necessary. Good or bad practice? -
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?) -
Should I be checking block_given? in delete_if, et. al.? Should I be
explicitly declaring a &blk argument?
Thanks for any tips.
- donald