Skip to content

Instantly share code, notes, and snippets.

@chrisortman
Created July 21, 2020 13:52
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 chrisortman/1d02179c60c5c95a4d59a51a7967f081 to your computer and use it in GitHub Desktop.
Save chrisortman/1d02179c60c5c95a4d59a51a7967f081 to your computer and use it in GitHub Desktop.
defmodule Common do
defmacro __using__(_opts) do
quote do
def validate(thing) do
Common.validate({__MODULE__, thing})
end
end
end
def validate({impl, thing}) do
IO.puts "Validate #{inspect(thing)} with #{impl}"
end
end
defmodule Customer do
use Common
end
defmodule Product do
use Common
end
Customer.validate([1,2,3])
Product.validate(%{:a => "A"})
# run with elixir sub.exs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment