Module: Animoto::Support::Hash

Defined in:
lib/animoto/support/hash.rb

Instance Method Summary collapse

Instance Method Details

#except(*keys) ⇒ Hash{Object=>Object}

Returns a new hash with all keys from this hash except the listed ones.

Parameters:

  • keys (Array<Object>)

    the keys to exclude

Returns:

  • (Hash{Object=>Object})

    a new hash without the listed keys



17
18
19
# File 'lib/animoto/support/hash.rb', line 17

def except *keys
  inject({}) { |h,(k,v)| h.merge(!keys.include?(v) ? {k => v} : {}) }
end

#only(*keys) ⇒ Hash{Object=>Object}

Returns a new hash with only the listed keys from this hash.

Parameters:

  • keys (Array<Object>)

    the keys to include

Returns:

  • (Hash{Object=>Object})

    a new hash with only the listed keys



9
10
11
# File 'lib/animoto/support/hash.rb', line 9

def only *keys
  inject({}) { |h,(k,v)| h.merge(keys.include?(k) ? {k => v} : {}) }
end