Last active
January 1, 2016 16:49
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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