O'Reilly logo

Programming Elixir by Dave Thomas

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Use and __using__

In one sense, use is a trivial function. You pass it a module along with an optional argument, and it invokes the function or macro __using__ in that module, passing it the argument.

Yet this simple interface gives you a powerful extension facility. For example, in our unit tests we write use ExUnit.Case and we get the test macro and assertion support. When we write an OTP server, we write use GenServer and we get both a behaviour that documents the gen_server callback and default implementations of those callbacks.

Typically, the __using__ callback will be implemented as a macro, as it will be used to invoke code in the original module.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required