From: Yasushi Shoji Date: 2001-01-07T07:31:47+09:00 Subject: [ruby-talk:8766] Re: bug?? At Sat, 6 Jan 2001 13:00:46 +0900, Mathieu Bouchard wrote: > > > for the compatibility, the default Hash#key_missing should be > > class Hash > > def key_missing(key) > > nil > > end > > end > > And my question is what functionality am I missing compare to > > Hash@default and its accessors? (other than compatibility) > > well, if instead it's > > class Hash > def key_missing(key) > default > end > end > > then I don't think you're missing any functionality. Except that #[] (and > such) call the internal Hash#default directly, so trying to > overload/redefine it does not work. Hash#default and its accessors were added to prevent error with code like: hash = {} ... hash["foo"] += 1 after the change so that nil + 1 yields error. [ruby-list:26602] so having two ways (default and key_missing) to fix the same thing isn't good IMHO. Anyway, if we didn't have Hash@default yet, I'd vote for #key_missing for sure, but don't know it worth breaking backward compatibity now. I'll leave that decision for Matz. -- yashi