Sha256: e0d50e25c2a58776c92da724f2cecbd4a1303892bb5a42c294a6a2b62b337f6f

Contents?: true

Size: 858 Bytes

Versions: 48

Compression:

Stored size: 858 Bytes

Contents

class Hash
  # Merges self with another hash, recursively.
  #
  # This code was lovingly stolen from some random gem:
  # http://gemjack.com/gems/tartan-0.1.1/classes/Hash.html
  #
  # Thanks to whoever made it.
  def deep_merge(hash)
    target = dup
    hash.keys.each do |key|
      if hash[key].is_a? Hash and self[key].is_a? Hash
        target[key] = target[key].deep_merge(hash[key])
        next
      end
      target[key] = hash[key]
    end

    target
  end

  def to_symbol_keys
    inject({}) do |memo, (k, v)|
      if v.is_a? Hash
        memo[k.to_sym] = v.to_symbol_keys
      else
        memo[k.to_sym] = v
      end

      memo
    end
  end

  def to_string_keys
    inject({}) do |memo, (k, v)|
      if v.is_a? Hash
        memo[k.to_s] = v.to_string_keys
      else
        memo[k.to_s] = v
      end

      memo
    end
  end
end

Version data entries

48 entries across 48 versions & 2 rubygems

Version Path
octopress-deploy-1.3.0 lib/octopress-deploy/core_ext.rb
octopress-deploy-1.2.8 lib/octopress-deploy/core_ext.rb
octopress-deploy-1.2.7 lib/octopress-deploy/core_ext.rb
octopress-deploy-1.2.6 lib/octopress-deploy/core_ext.rb
octopress-deploy-1.2.5 lib/octopress-deploy/core_ext.rb
octopress-deploy-1.2.4 lib/octopress-deploy/core_ext.rb
octopress-deploy-1.2.3 lib/octopress-deploy/core_ext.rb
octopress-deploy-1.2.2 lib/octopress-deploy/core_ext.rb
octopress-deploy-1.2.1 lib/octopress-deploy/core_ext.rb
octopress-deploy-1.2.0 lib/octopress-deploy/core_ext.rb
octopress-deploy-1.1.0 lib/octopress-deploy/core_ext.rb
octopress-deploy-1.0.5 lib/octopress-deploy/core_ext.rb
octopress-deploy-1.0.4 lib/octopress-deploy/core_ext.rb
octopress-deploy-1.0.3 lib/octopress-deploy/core_ext.rb
octopress-deploy-1.0.2 lib/octopress-deploy/core_ext.rb
octopress-deploy-1.0.1 lib/octopress-deploy/core_ext.rb
octopress-deploy-1.0.0 lib/octopress-deploy/core_ext.rb
octopress-deploy-1.0.0.rc.13 lib/octopress-deploy/core_ext.rb
octopress-deploy-1.0.0.rc.12 lib/octopress-deploy/core_ext.rb
octopress-deploy-1.0.0.rc.11 lib/octopress-deploy/core_ext.rb