3 # This class is implemented using composition rather than inheritance so
4 # that we have control over what operations it exposes to peers.
8 def initialize(hash={})
14 other_obj.class == self.class &&
15 other_obj.hash == self.hash
23 @hash[normalize(key)] = value
35 @hash.has_key? normalize(name)
51 Hashish.new(@hash.merge(other_hash))
54 def merge!(other_hash)
55 @hash.merge! other_hash
65 @hash.each do |key, value|
66 if value.kind_of? String
70 elsif value.kind_of? Array
71 value = "[#{value.join(", ")}]"
74 str += " #{key}: #{value},"
77 str = str[0...-1] + " }"
83 # Hashishify all the things!
85 @hash.each do |key, value|
86 if @hash[key].kind_of? Hash
87 @hash[key] = Hashish.new(value)
88 elsif @hash[key].kind_of? Array
89 @hash[key].each_index do |index|
90 element = @hash[key][index]
91 if element.kind_of? Hash
92 @hash[key][index] = Hashish.new(element)
100 if @hash.has_key? key
102 elsif key.is_a? String
104 elsif key.is_a? Symbol