Created
January 17, 2014 00:09
-
-
Save AlexanderEkdahl/8466023 to your computer and use it in GitHub Desktop.
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
defmodule RandomModule do | |
defmacro __using__(module) do | |
quote do | |
import RandomModule | |
Module.register_attribute __MODULE__, :attributes, accumulate: true | |
def run do | |
RandomModule.run @attributes | |
end | |
end | |
end | |
def run(attributes) do | |
IO.puts attributes | |
end | |
defmacro attribute(name) do | |
quote do: @attributes unquote(name) | |
end | |
end | |
# Then used as this | |
defmodule DSL do | |
use RandomModule | |
attribute :name | |
attribute :id | |
end | |
DSL.run # should output my attributes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment