Sha256: 50a6d6c0fc9cd8226023c2a9a2e39354d2414cb7d4316c6772dc9132df31b756

Contents?: true

Size: 777 Bytes

Versions: 6

Compression:

Stored size: 777 Bytes

Contents

class Hash
  def slice(*keep_keys)
    h = {}
    keep_keys.each { |key| h[key] = fetch(key) }
    h
  end unless Hash.method_defined?(:slice)

  def except(*less_keys)
    slice(*keys - less_keys)
  end unless Hash.method_defined?(:except)

  def deep_symbolize_keys
    inject({}) { |result, (key, value)|
      value = value.deep_symbolize_keys if value.is_a?(Hash)
      result[(key.to_sym rescue key) || key] = value
      result
    }
  end unless Hash.method_defined?(:deep_symbolize_keys)

  # deep_merge_hash! by Stefan Rusterholz, see http://www.ruby-forum.com/topic/142809
  def deep_merge(other)
    merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
    merge(other, &merger)
  end unless Hash.method_defined?(:deep_merge)
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
hashr-0.0.13 lib/hashr/core_ext/ruby/hash.rb
hashr-0.0.12 lib/hashr/core_ext/ruby/hash.rb
hashr-0.0.11 lib/hashr/core_ext/ruby/hash.rb
hashr-0.0.10 lib/hashr/core_ext/ruby/hash.rb
hashr-0.0.9 lib/hashr/core_ext/ruby/hash.rb
hashr-0.0.8 lib/hashr/core_ext/ruby/hash.rb