Skip to content

Instantly share code, notes, and snippets.

@bonjourmauko
Created June 20, 2012 19:57
Show Gist options
  • Save bonjourmauko/2961845 to your computer and use it in GitHub Desktop.
Save bonjourmauko/2961845 to your computer and use it in GitHub Desktop.
A function to filter the params sent to a REST API endpoint
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