Today I Learned

hashrocket A Hashrocket project

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"
See More #elixir TILs
Looking for help? At Hashrocket, we 💜 Elixir! From our many Elixir client projects, to sponsoring the Chicago Elixir Meetup, to the source code for this application, we are invested in this community. Contact us today to talk about your Elixir project.