Module: TopHat::HashOnly

Defined in:
lib/tophat/core_extensions.rb

Instance Method Summary collapse

Instance Method Details

#only(*keys) ⇒ Object

Returns a new hash with only the given keys.



4
5
6
# File 'lib/tophat/core_extensions.rb', line 4

def only(*keys)
  reject {|key, value| !keys.include?(key) }
end

#only!(*keys) ⇒ Object

Replaces the hash without only the given keys.



9
10
11
# File 'lib/tophat/core_extensions.rb', line 9

def only!(*keys)
  replace(only(*keys))
end