On 5/17/07, Ball, Donald A Jr (Library) <donald.ball / nashville.gov> 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 > > <snip> > > 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?) No that is not a good way I am afraid. Please note that one cannot freeze instant variables - I have a reason to be picky here, I believe - but the objects they are referring to. Do you see the implications of a "deep" freeze now? The whole program will probably get cold feet ;) as objects just referenced in our object would be frozen. However what you are doing is clever of course, you freeze the objects you have created as containers for other objects without freezing the objects the container references, do you see how bad it would be again if your SortedHash froze all contained objects? > > 4. Should I be checking block_given? in delete_if, et. al.? Should I be > explicitly declaring a &blk argument? I prefer to declare &blk, because it is easier to pass it to another method needing a block, just compare def a &blk b &blk if blk end v.s. def a b &Proc.new if block_given? end However passing &blk is much slower if memory serves right. Cheers Robert > > Thanks for any tips. > > - donald > > -- You see things; and you say Why? But I dream things that never were; and I say Why not? -- George Bernard Shaw