Skip to content

Instantly share code, notes, and snippets.

@josevalim
Forked from Andy-Richards/gist:6916317
Last active December 25, 2015 04:19
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 josevalim/6916427 to your computer and use it in GitHub Desktop.
Save josevalim/6916427 to your computer and use it in GitHub Desktop.
% from my unit tests
foo = 10
assert 10 == my_macro(:foo)
assert 10 == my_macro("foo")
% macro
defmacro my_macro(some_var) when is_atom(some_var) do
quote do
var!(unquote(some_var))
end
end
defmacro my_macro(some_var) when is_binary(some_var) do
quote do
var!(unquote(binary_to_atom(some_var)))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment