Skip to content

Instantly share code, notes, and snippets.

@AlexanderEkdahl
Created January 17, 2014 00:09
Show Gist options
  • Save AlexanderEkdahl/8466023 to your computer and use it in GitHub Desktop.
Save AlexanderEkdahl/8466023 to your computer and use it in GitHub Desktop.
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