Skip to content

Instantly share code, notes, and snippets.

@jjuarez
Last active December 23, 2015 23:49
Show Gist options
  • Save jjuarez/6712453 to your computer and use it in GitHub Desktop.
Save jjuarez/6712453 to your computer and use it in GitHub Desktop.
How to validate a set of options fast and classy
module YourModule
VALID_OPTIONS = [ :foo, :bar ]
def your_method(parameter, options={ })
invalid_options = options.keys - VALID_OPTIONS
raise ArgumentError, "invalid option(s): #{invalid_options.join(', ')}" if invalid_options.any?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment