Sha256: a52f822b84a5d55ba6693cf32932a8019a92a1bacbd62157b10789d7db807dac

Contents?: true

Size: 459 Bytes

Versions: 8

Compression:

Stored size: 459 Bytes

Contents

class Hash

  # any hashes within the hash will also be merged to the level specifid
  def merge_deep(hash2, level=1)
    if level == 1
      tmp_opts = {}
      self.each do |k,v|
        if (v.is_a?(Hash) and hash2[k].is_a?(Hash))
          tmp_opts[k] = v.merge(hash2[k])
        end
      end
      opts = self.merge(hash2)
      opts.merge!(tmp_opts)
      opts
    else
      raise NotImplementedError, "need to implement level > 1"
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mspire-0.4.9 lib/merge_deep.rb
mspire-0.3.0 lib/merge_deep.rb
mspire-0.3.1 lib/merge_deep.rb
mspire-0.3.9 lib/merge_deep.rb
mspire-0.4.2 lib/merge_deep.rb
mspire-0.4.4 lib/merge_deep.rb
mspire-0.4.5 lib/merge_deep.rb
mspire-0.4.7 lib/merge_deep.rb