Skip to content

Instantly share code, notes, and snippets.

@thiagoa
Created May 19, 2017 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thiagoa/1673f8ba044693a4a1b1a0357448ca25 to your computer and use it in GitHub Desktop.
Save thiagoa/1673f8ba044693a4a1b1a0357448ca25 to your computer and use it in GitHub Desktop.
defmodule FunctionLogger do
defmacro __using__(_) do
quote do
import Kernel, except: [def: 2]
import FunctionLogger
end
end
defmacro def(fun_def, do: block) do
quote do
Kernel.def unquote(fun_def) do
fn -> unquote(block) end.()
|> FunctionLogger.log
end
end
end
def log(value) do
IO.inspect "Return value is #{value}"
value
end
end
defmodule Example do
use FunctionLogger
def three do
3
end
def four do
4
end
def n(n) do
n
end
end
IO.puts Example.n(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment