Skip to content

Instantly share code, notes, and snippets.

@jashkenas
Created March 5, 2012 15:42
Show Gist options
  • Save jashkenas/1978885 to your computer and use it in GitHub Desktop.
Save jashkenas/1978885 to your computer and use it in GitHub Desktop.
# Select only a sub-set of passed parameters. Useful for whitelisting
# attributes from the params hash before performing a mass-assignment.
def pick(hash, *keys)
filtered = {}
hash.each {|key, value| filtered[key.to_sym] = value if keys.include?(key.to_sym) }
filtered
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment