Created
June 20, 2012 19:57
-
-
Save bonjourmauko/2961845 to your computer and use it in GitHub Desktop.
A function to filter the params sent to a REST API endpoint
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 | |
# Public: Filters a hash to check only for those elements desired | |
# | |
# Examples | |
# | |
# hash = { uno: "uno", dos: "dos", tres: "tres" } | |
# whitelist = [ :uno, :dos ] | |
# hash.filter whitelist | |
# # => { uno: "uno", dos: "dos" } | |
# | |
# Returns a Hash | |
def filter ary | |
select { |k| ary.include? k } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment