lib/hashr.rb in hashr-0.0.17 vs lib/hashr.rb in hashr-0.0.18

- old
+ new

@@ -39,18 +39,24 @@ replace((deep_hashrize(definition.deep_merge((data || {}).deep_symbolize_keys)))) deep_defaultize(self) (class << self; self; end).class_eval(&block) if block_given? end - def [](key) + def [](key, default = nil) + store(key.to_sym, Hashr.new(default)) if default && !key?(key) super(key.to_sym) end def []=(key, value) super(key.to_sym, value.is_a?(Hash) ? self.class.new(value, {}) : value) end + def set(path, value, stack = []) + tokens = path.to_s.split('.') + tokens.size == 1 ? self[path] = value : self[tokens.shift, Hashr.new].set(tokens.join('.'), value, stack) + end + def respond_to?(name) true end def method_missing(name, *args, &block) @@ -115,6 +121,5 @@ end hash end end -