lib/gumdrop/util/hash_object.rb in gumdrop-1.0.2 vs lib/gumdrop/util/hash_object.rb in gumdrop-1.0.3
- old
+ new
@@ -5,10 +5,13 @@
# All keys are symbols, internally
def [](key)
super(key.to_sym)
end
def []=(key, value)
+ if value.is_a? Hash
+ value= HashObject.from value, true
+ end
super(key.to_sym, value)
end
def method_missing(sym, *args, &block)
if self.has_key? sym.to_s or self.has_key? sym
@@ -57,11 +60,18 @@
else
super(other_hash, &block)
end
end
- def self.from(hash={})
+ def self.from(hash={}, recurse=true)
h= new
+ if recurse
+ hash.each do |key, value|
+ if value.is_a? Hash
+ hash[key]= HashObject.from value
+ end
+ end
+ end
h.merge!(hash)
h
end
end
\ No newline at end of file