Referencing other module in Elixir

There are several different ways of referencing a function in another module.

The direct:

MyModule.SubModule.hello

You can also alias the module so that a shorter name can be used:

alias MyModule.SubModule
Submodule.hello

You can import a module so that all the functions are treated as local to this module:

import MyModule.SubModule
hello

You can require a module so that you can use the macros defined in that module.

You can use a module to run the __using__ function from that module in your context.

These don’t have to be at the top of the module, you can use them within a function to restrict scope (not so sure about using __using__ this way…).

These also have parameterized versions so that you can choose what to import (only some, exclude some, rename them).

This can make them seem complex …

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s