def self.[](*args)
default = []
if args.size == 2 && args.last.is_a?(Hash)
default = args.shift
elsif !args.first.is_a?(Hash) && args.size % 2 == 1
default = args.shift
end
if args.size == 1 && args.first.is_a?(Hash)
args[0] = args.first.inject({}) { |hash, (key, value)|
unless value.is_a?(default.class)
value = (default.dup << value)
end
hash[key] = value
hash
}
else
index = 0
args.map! { |value|
unless index % 2 == 0 || value.is_a?(default.class)
value = (default.dup << value)
end
index += 1
value
}
end
map = new
map.instance_variable_set(:@hash, Hash[*args])
map.default = default
map
end