Module: Cms::Extensions::Hash

Defined in:
lib/cms/extensions/hash.rb

Instance Method Summary collapse

Instance Method Details

#except(*args) ⇒ Object

Returns a copy of the hash without the keys passed as arguments



5
6
7
# File 'lib/cms/extensions/hash.rb', line 5

def except(*args)
  reject {|k,v| args.include?(k) }
end

#extract!(*keys) ⇒ Object

This takes a list of keys and returns a new hash containing the key/values that match the keys passed in. This will also remove the keys from this hash



12
13
14
15
16
17
# File 'lib/cms/extensions/hash.rb', line 12

def extract!(*keys)
  keys.inject({}) do |hash, key|
    hash[key] = delete(key) if has_key?(key)
    hash
  end
end