Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
defmodule MyMacros do
defmacro my_macro() do
module = __CALLER__.module
Module.get_attribute(module, :foo) |> IO.inspect(label: "outside quote")
quote do
Module.get_attribute(unquote(module), :foo) |> IO.inspect(label: "with unquoted module")
Module.get_attribute(__MODULE__, :foo) |> IO.inspect(label: "with __MODULE__")
end
end
end
defmodule UseMacros do
require MyMacros
@foo bar: 1
MyMacros.my_macro()
end
outside quote: nil
with unquoted module: [bar: 1]
with __MODULE__: [bar: 1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.