Using __using__ for use with the `use` macro
You might run across the use
macro while doing something like.
use GenServer
This sets up the module to be able to do special things with the special module GenServer
.
Behind the scenes GenServer
implements
defmacro __using__(_opts) do
to ensure that the module is setup correctly for use with GenServer
.
You can experiment with implementing __using__
inside of IEX like so:
iex > defmodule Fruit do
... > defmacro __using__(_opts) do
... > quote do
... > IO.puts "Good to see you've added Fruit to your meal"
... > end
... > end
... > end
iex > defmodule Meal do
... > use Fruit
... > end
"Good to see you've added Fruit to your meal"
Tweet