Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
defmodule Overrider do
defmacro __using__(_) do
quote do
import Kernel, except: [def: 2]
import Overrider
end
end
defmacro def(fun_def, opts) do
quote do
Kernel.def unquote(fun_def) do
IO.puts "Calling #{inspect unquote(Macro.escape(fun_def))}"
unquote(opts[:do])
end
end
end
end
defmodule Test do
use Overrider
def add(x, y) do
x + y
end
end
Test.add(2, 3)
|> IO.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment