Sha256: 4364b673711dd74a8af9480820669e5168082163b50c3114fadb766a08abd5ae
Contents?: true
Size: 648 Bytes
Versions: 6
Compression:
Stored size: 648 Bytes
Contents
class Hash def deep_merge(other_hash) dup.deep_merge!(other_hash) end def deep_merge!(other_hash) other_hash.each_pair do |k,v| tv = self[k] self[k] = \ if tv.is_a?(Hash) && v.is_a?(Hash) tv.deep_merge(v) elsif tv.is_a?(Array) && v.is_a?(Array) tv + v else v end end self end def underscore_keys self.inject({}) do |h, (k,v)| h[k.to_s.underscore] = \ case v when Hash v.underscore_keys when Array v.map { |i| i.is_a?(Hash) ? i.underscore_keys : i } else v end; h end end end
Version data entries
6 entries across 6 versions & 1 rubygems