Skip to content

Instantly share code, notes, and snippets.

@mrmicahcooper
Created August 29, 2018 03:19
Show Gist options
  • Select an option

  • Save mrmicahcooper/f24df93a7cd52778e59af4ea156b0151 to your computer and use it in GitHub Desktop.

Select an option

Save mrmicahcooper/f24df93a7cd52778e59af4ea156b0151 to your computer and use it in GitHub Desktop.
defmodule TimeMacro do
defmacro deftime(function_name, [do: block] = expression) do
quote do
def unquote(function_name) do
start_time = NaiveDateTime.utc_now()
result = unquote(block)
finish_time = NaiveDateTime.utc_now()
IO.puts("sent #{start_time} and #{finish_time}")
result
end
end
end
end
defmodule Test do
require TimeMacro
TimeMacro.deftime show(var \\ "") do
"the var is #{var}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment