Created
April 6, 2017 17:36
-
-
Save myronmarston/f8cf2872351fb28e9d59cee9b8cd98a4 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 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 |
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
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