Sha256: 83a2b004972ffc55f84524dff50bb0769286f54a29aa53c0c72f5d27b774ce04

Contents?: true

Size: 632 Bytes

Versions: 22

Compression:

Stored size: 632 Bytes

Contents

class Hash
  def deep_merge(other_hash, &block)
    dup.deep_merge!(other_hash)
  end

  def deep_merge!(other_hash, &block)
    merge!(other_hash) do |key, this_val, other_val|
      if this_val.is_a?(Hash) && other_val.is_a?(Hash)
        this_val.deep_merge(other_val, &block)
      elsif block_given?
        block.call(key, this_val, other_val)
      else
        other_val
      end
    end
  end

  def slice(*keep_keys)
    h                                              = {}
    keep_keys.each { |key| has_key?(key) && h[key] = fetch(key, nil) }
    h
  end

  def except(*less_keys)
    slice(*keys - less_keys)
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
swagalicious-2.0.0 lib/core/ext/hash.rb
swagalicious-1.1.2 lib/core/ext/hash.rb
swagalicious-1.1.1 lib/core/ext/hash.rb
swagalicious-1.1.0 lib/core/ext/hash.rb
swagalicious-1.0.0 lib/core/ext/hash.rb
swagalicious-0.5.3 lib/core/ext/hash.rb
swagalicious-0.5.2 lib/core/ext/hash.rb
swagalicious-0.5.1 lib/core/ext/hash.rb
swagalicious-0.5.0 lib/core/ext/hash.rb
swagalicious-0.4.9 lib/core/ext/hash.rb
swagalicious-0.4.8 lib/core/ext/hash.rb
swagalicious-0.4.7 lib/core/ext/hash.rb
swagalicious-0.4.6 lib/core/ext/hash.rb
swagalicious-0.4.5 lib/core/ext/hash.rb
swagalicious-0.4.4 lib/core/ext/hash.rb
swagalicious-0.4.3 lib/core/ext/hash.rb
swagalicious-0.4.2 lib/core/ext/hash.rb
swagalicious-0.4.1 lib/core/ext/hash.rb
swagalicious-0.4.0 lib/core/ext/hash.rb
swagalicious-0.3.1 lib/core/ext/hash.rb