Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/hash_keys.rb
Instance Method Summary collapse
-
#reject_keys(*keys) ⇒ Object
(also: #eject_keys)
Return a hash containing everything except the named keys.
-
#select_keys(*keys) ⇒ Object
(also: #retain_keys)
Return a hash containing only the named keys.
Instance Method Details
#reject_keys(*keys) ⇒ Object Also known as: eject_keys
Return a hash containing everything except the named keys
10 11 12 |
# File 'lib/hash_keys.rb', line 10 def reject_keys *keys reject{|k, _| keys.include? k} end |
#select_keys(*keys) ⇒ Object Also known as: retain_keys
Return a hash containing only the named keys
3 4 5 |
# File 'lib/hash_keys.rb', line 3 def select_keys *keys select{|k, _| keys.include? k} end |