Skip to content

Instantly share code, notes, and snippets.

@yctay
Last active January 1, 2016 16:49
Show Gist options
  • Save yctay/8173562 to your computer and use it in GitHub Desktop.
Save yctay/8173562 to your computer and use it in GitHub Desktop.
Extension of the `key?` method to check for existence of multiple keys in a hash.
class Hash
# Extension of the `key?` method to check for existence of multiple keys in
# a hash.
#
# Returns true if all keys matches, false if hash has missing keys.
# Returns true if hash has more keys than specified in array.
def keys?(array)
!array.map { |k| self.key?(k) }.include? false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment