Module: Animoto::Support::Hash
- Defined in:
- lib/animoto/support/hash.rb
Instance Method Summary collapse
-
#except(*keys) ⇒ Hash{Object=>Object}
Returns a new hash with all keys from this hash except the listed ones.
-
#only(*keys) ⇒ Hash{Object=>Object}
Returns a new hash with only the listed keys from this hash.
Instance Method Details
#except(*keys) ⇒ Hash{Object=>Object}
Returns a new hash with all keys from this hash except the listed ones.
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.
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 |