Skip to content

Instantly share code, notes, and snippets.

@Andy-Richards
Created December 4, 2013 10:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Andy-Richards/7785272 to your computer and use it in GitHub Desktop.
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
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