Skip to content

Instantly share code, notes, and snippets.

@ericdke
Created March 28, 2014 10:57
Show Gist options
  • Save ericdke/9830115 to your computer and use it in GitHub Desktop.
Save ericdke/9830115 to your computer and use it in GitHub Desktop.
Get hash content except some keys (filter hash)
def filter(hsh, *keys)
hsh.reject { |k, _| keys.include? k }
end
# Usage
histogram = {
monday: 5,
tuesday: 7,
wednesday: 10,
thursday: 18,
friday: 7,
saturday: 2,
sunday: 0
}
filter(histogram, :saturday, :sunday)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment