I wanted to extend the Hash class so that all hashes get same default_proc when they're created. So I put this in my file:
class Hash
def initialize
self.default_proc = proc { |hash, key| raise NameError, "#{key} is not allowed" }
end
end
This works fine if I use this syntax
h = Hash.new
but not if I use
h = {}
Playing with it, it seems that the latter syntax doesn't call initialize. Is there an "iron-clad" way to achieve setting the default_proc for all hashes?