Created
August 29, 2018 03:19
-
-
Save mrmicahcooper/f24df93a7cd52778e59af4ea156b0151 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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