Skip to content

Instantly share code, notes, and snippets.

@thetamind
Created July 2, 2018 07:11
Show Gist options
  • Save thetamind/817be56b3cb17d0ad928eba5dcb12823 to your computer and use it in GitHub Desktop.
Save thetamind/817be56b3cb17d0ad928eba5dcb12823 to your computer and use it in GitHub Desktop.
defmodule Bug.Default do
defmacro __using__(_) do
quote do
@impl Bug.Server
def one(), do: "Fallback"
def two(), do: "Fallback"
defoverridable Bug.Server
end
end
end
defmodule Bug.Server do
@callback one() :: String.t()
@callback two() :: String.t()
defmacro __using__(_) do
quote do
@behaviour unquote(__MODULE__)
use Bug.Default
end
end
end
defmodule Bug.Plugin do
defmacro __using__(_) do
quote do
@impl Bug.Server
def one() do
super() <> " + Plugin"
end
defoverridable Bug.Server
end
end
end
defmodule MyApp do
use Bug.Server
use Bug.Plugin
def one() do
super() <> " <- MyApp"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment