class Hash alias :old_default :default def default(*args) ret = old_default(*args) ignore_these = [NilClass, TrueClass, FalseClass, Float, Symbol, Rational, Integer] case ret when *ignore_these: ret else ret.dup end end end # This is to prevent weird behavior such as this: # h = Hash.new([]) # h['a'].push(1) -> [1] # h['a'].push(2) -> [1,2] # h['b'].push(3) -> [1,2,3] # h['a'] -> [1,2,3] # h['b'] -> [1,2,3] # # Since no assignments are being made, the intuitive behavior would be thus: # h = Hash.new([]) # h['a'].push(1) -> [1] # h['a'].push(2) -> [2] # h['b'].push(3) -> [3] # h['a'] -> [] # h['b'] -> []