Skip to content

Instantly share code, notes, and snippets.

@jaredatron
Created May 2, 2009 01:22
Show Gist options
  • Select an option

  • Save jaredatron/105352 to your computer and use it in GitHub Desktop.

Select an option

Save jaredatron/105352 to your computer and use it in GitHub Desktop.
class Hash
# Like has_key? but accepts an list of keys and returns true of self has every
# key in the array
def has_keys?(key, *other_keys)
other_keys.unshift key
other_keys.flatten.all?{ |k| self.has_key? k }
end
# Like has_key? but accepts a list of keys and returns true of self has any
# key in the array
def has_any_key?(key, *other_keys)
other_keys.unshift key
other_keys.flatten.any?{ |k| self.has_key? k }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment