Sha256: f4283c035b71f1873f1de19830fa95f0ccf1d44d11cc3609037ac72394c14ee9
Contents?: true
Size: 1.57 KB
Versions: 33
Compression:
Stored size: 1.57 KB
Contents
module Metanorma module Utils module Array def stringify_all_keys map do |v| case v when ::Hash, ::Array v.stringify_all_keys else v end end end def symbolize_all_keys map do |v| case v when ::Hash, ::Array v.symbolize_all_keys else v end end end end end end module Metanorma module Utils module Hash def stringify_all_keys result = {} each do |k, v| result[k.to_s] = case v when ::Hash, ::Array v.stringify_all_keys else v end end result end def symbolize_all_keys result = {} each do |k, v| result[k.to_sym] = case v when ::Hash, ::Array v.symbolize_all_keys else v end end result end def deep_merge(second) merger = proc { |_, v1, v2| if ::Hash === v1 && ::Hash === v2 v1.merge(v2, &merger) elsif ::Array === v1 && ::Array === v2 v1 | v2 elsif [:undefined, nil, :nil].include?(v2) v1 else v2 end } merge(second.to_h, &merger) end end end end
Version data entries
33 entries across 33 versions & 1 rubygems