Skip to content

Instantly share code, notes, and snippets.

@trestrantham
Last active August 29, 2015 14:03
Show Gist options
  • Save trestrantham/1e7ac76f301ec6d3ec77 to your computer and use it in GitHub Desktop.
Save trestrantham/1e7ac76f301ec6d3ec77 to your computer and use it in GitHub Desktop.
defmodule Test do
Module.register_attribute __MODULE__, :config, accumulate: true, persist: false
@before_compile __MODULE__
defmacro __before_compile__(_) do
quote do
Module.put_attribute(__MODULE__, :config, { :foo, "foo" })
end
end
def env, do: @config
end
# == Compilation error on file lib/test.ex ==
# ** (UndefinedFunctionError) undefined function: Test.__before_compile__/1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment