Last active
March 9, 2020 02:31
-
-
Save MatheusRich/847b9a32d44bbee57254ca85b43a8c86 to your computer and use it in GitHub Desktop.
Macro for creating nested properties such as properties based on hash keys
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
macro define_option_property(*options) | |
{% for option in options %} | |
def {{option.id}}? | |
@options[:{{option}}] | |
end | |
{% end %} | |
end | |
class CLI | |
OPTIONS = { | |
:suppress_errors => false, | |
:colored_output => true, | |
} | |
{% for option in OPTIONS.keys %} | |
define_option_property {{option.id}} | |
{% end %} | |
def initialize | |
@options = OPTIONS | |
end | |
end | |
cli = CLI.new | |
cli.colored_output? # => false | |
cli.suppress_errors? # => false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment