Skip to content

Instantly share code, notes, and snippets.

@lucasmazza
Created March 19, 2019 21:20
Show Gist options
  • Save lucasmazza/1a1fc04464a93316fbc5993b922bd3d9 to your computer and use it in GitHub Desktop.
Save lucasmazza/1a1fc04464a93316fbc5993b922bd3d9 to your computer and use it in GitHub Desktop.
defmodule MyApp.Delegator do
defmacro __using__(opts) do
quote do
def unquote(:"$handle_undefined_function")(name, args) do
apply(Keyword.get(unquote(opts), :target), name, args)
end
end
end
end
defmodule MyApp.ACMECO do
def hello(), do: "hello"
def goodbye(), do: "goodbye"
end
defmodule MyApp.ACMECO.Staging do
use MyApp.Delegator, target: MyApp.ACMECO
def hello(), do: "HELLO YALL"
end
IO.inspect(MyApp.ACMECO.Staging.hello())
IO.inspect(MyApp.ACMECO.Staging.goodbye())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment