lib/hash.rb in hash_dot-2.2.0 vs lib/hash.rb in hash_dot-2.3.0

- old
+ new

@@ -31,17 +31,31 @@ return super(method, include_all) unless to_dot? prop = create_prop(method) return true if key?(prop) super(method, include_all) end - + private + def dotify_obj(obj, use_default: false) + case obj + when Array + obj.each do |el| + dotify_obj(el) + end + when Hash + dotify_hash(obj, use_default: use_default) + # else no-op + end + end + def dotify_hash(hash, use_default: false) hash.use_dot_syntax = true hash.hash_dot_use_default = use_default - hash.keys.each { |key| dotify_hash(hash[key], use_default: use_default) if hash[key].is_a?(Hash) } + hash.each_value do |val| + dotify_obj(val) + end end def to_dot? use_dot_syntax || self.class.use_dot_syntax end