Last active
September 15, 2015 05:07
-
-
Save cpjk/bf87eec0ed8c107c8117 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
# file1.ex | |
defmodule A do | |
defmacro __using__(_env) do | |
quote do | |
Module.register_attribute __MODULE__, :rules, accumulate: true | |
end | |
end | |
defmacro register() do | |
@rules | |
|> Enum.each fn(x) -> | |
#.... | |
#.... | |
end | |
quote do | |
# something | |
end | |
end | |
defmacro define_rule() do | |
quote do | |
@rules {"rule"} | |
end | |
end | |
end | |
require A | |
# file2.ex | |
defmodule B do | |
use A | |
A.define_rule | |
A.register # @rules is not yet defined when this macro is expanded | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment