Last active
December 23, 2015 23:49
-
-
Save jjuarez/6712453 to your computer and use it in GitHub Desktop.
How to validate a set of options fast and classy
This file contains 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
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