Last active
October 19, 2015 16:04
-
-
Save xdougx/1c6c9954f028e53b8346 to your computer and use it in GitHub Desktop.
Macro for Cystal to include class property
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 ClassProperty | |
macro class_property(*names) | |
class_getter {{*names}} | |
class_setter {{*names}} | |
end | |
macro class_property?(*names) | |
class_getter? {{*names}} | |
class_setter {{*names}} | |
end | |
macro class_property!(*names) | |
getter! {{*names}} | |
setter {{*names}} | |
end | |
macro class_setter(*names) | |
{% for name in names %} | |
def self.{{name}}=(value) | |
@@{{name}} = value | |
end | |
{% end %} | |
end | |
macro class_getter(*names) | |
{% for name in names %} | |
def self.{{name}} | |
@@{{name}} | |
end | |
{% end %} | |
end | |
macro class_getter?(*names) | |
{% for name in names %} | |
def {{name}}? | |
@@{{name}} | |
end | |
{% end %} | |
end | |
macro class_getter!(*names) | |
{% for name in names %} | |
def {{name}}? | |
@@{{name}} | |
end | |
def {{name}} | |
@@{{name}}.not_nil! | |
end | |
{% end %} | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment