Skip to content

Instantly share code, notes, and snippets.

@sasa1977
Created April 28, 2015 16:24
Show Gist options
  • Save sasa1977/a14f8dd76fe437668ac1 to your computer and use it in GitHub Desktop.
Save sasa1977/a14f8dd76fe437668ac1 to your computer and use it in GitHub Desktop.
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