Created
December 4, 2013 10:15
-
-
Save Andy-Richards/7785272 to your computer and use it in GitHub Desktop.
Dynamically generate funs from a list of fun names with a __before_compile__ hook
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 A do | |
defmacro __before_compile__(_env) do | |
Enum.each(["a", "b"], fn(name) -> | |
quote do | |
def unquote(name), do: unquote(name) | |
end | |
end) | |
quote do | |
Enum.each(["c", "d"], fn(name) -> | |
def name, do: name | |
end) | |
end | |
end | |
end | |
defmodule B do | |
@before_compile A | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment