Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/hash_extension.rb
Instance Method Summary collapse
-
#only(*selected_keys) ⇒ Object
Returns a hash that only contains keys that are passed in selected_keys.
Instance Method Details
#only(*selected_keys) ⇒ Object
Returns a hash that only contains keys that are passed in selected_keys. This is different from Hash#select, since that method returns an array of arrays.
4 5 6 7 8 |
# File 'lib/hash_extension.rb', line 4 def only(*selected_keys) cpy = self.dup keys.each { |key| cpy.delete(key) unless selected_keys.map(&:to_s).include?(key) } cpy end |