Skip to content

Instantly share code, notes, and snippets.

@MatheusRich
Last active March 9, 2020 02:31
Show Gist options
  • Save MatheusRich/847b9a32d44bbee57254ca85b43a8c86 to your computer and use it in GitHub Desktop.
Save MatheusRich/847b9a32d44bbee57254ca85b43a8c86 to your computer and use it in GitHub Desktop.
Macro for creating nested properties such as properties based on hash keys
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