Sha256: d924ebf4086e237cb941fcb1f82964960899772c6c45c47f392723eefdce76f4

Contents?: true

Size: 487 Bytes

Versions: 2

Compression:

Stored size: 487 Bytes

Contents

module DataAccessible
  module HashMethods
    module_function

    def deep_merge(original_data, new_data)
      merger = proc do |_key, v1, v2|
        v1.is_a?(Hash) && v2.is_a?(Hash) ? v1.merge(v2, &merger) : v2
      end

      original_data.merge(new_data, &merger)
    end

    def each_hash(data, &block)
      case data
        when Hash
          yield data
        when Array
          data.each { |element| each_hash(element, &block) }
      end
      data
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
data_accessible-1.0.2 lib/data_accessible/hash_methods.rb
data_accessible-1.0.1 lib/data_accessible/hash_methods.rb