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