Last active
December 17, 2015 22:19
-
-
Save cesarfigueroa/5681278 to your computer and use it in GitHub Desktop.
Hash extensions for including and excluding keys.
This file contains hidden or 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 | |
def only(*keys) | |
self.select { |key, _| keys.include?(key) } | |
end | |
def except(*keys) | |
self.reject { |key, _| keys.include?(key) } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For the mutable versions, use
select!
andreject!
instead, respectively.