5 # This class is implemented using composition rather than inheritance so
6 # that we have control over what operations it exposes to peers.
10 def initialize(hash={})
17 other_obj.class == self.class &&
18 other_obj.hash == self.hash
26 @hash[normalize(key)] = value
30 Hashish.new(JSON.parse(@hash.to_json))
42 @hash.has_key? normalize(name)
58 Hashish.new(@hash.merge(other_hash))
61 def merge!(other_hash)
62 @hash.merge! other_hash
72 @hash.each do |key, value|
73 if value.kind_of? String
77 elsif value.kind_of? Array
78 value = "[#{value.join(", ")}]"
81 str += " #{key}: #{value},"
84 str = str[0...-1] + " }"
90 # Hashishify all the things!
92 @hash.each do |key, value|
93 if @hash[key].kind_of? Hash
94 @hash[key] = Hashish.new(value)
95 elsif @hash[key].kind_of? Array
96 @hash[key].each_index do |index|
97 element = @hash[key][index]
98 if element.kind_of? Hash
99 @hash[key][index] = Hashish.new(element)
108 if @hash.has_key? key
110 elsif key.is_a? Symbol
122 @hash[key.to_s] = @hash.delete(key)