Method: Hash#only_keys?
- Defined in:
- lib/core/facets/hash/keys.rb
#only_keys?(*check_keys) ⇒ Boolean Also known as: has_only_keys?
Returns true if the hash contains only the given keys, otherwise false.
h = { :a => 1, :b => 2 }
h.has_only_keys?( :a, :b ) #=> true
h.has_only_keys?( :a ) #=> false
CREDIT: Trans
28 29 30 31 |
# File 'lib/core/facets/hash/keys.rb', line 28 def only_keys?(*check_keys) unknown_keys = self.keys - check_keys return unknown_keys.empty? end |