Skip to content

Instantly share code, notes, and snippets.

@xdougx
Last active October 19, 2015 16:04
Show Gist options
  • Save xdougx/1c6c9954f028e53b8346 to your computer and use it in GitHub Desktop.
Save xdougx/1c6c9954f028e53b8346 to your computer and use it in GitHub Desktop.
Macro for Cystal to include class property
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