cri.dev
about posts rss

elixir alias __module__

Published on
Tagged with elixir16 alias1 module2

Today I came across a line in a Elixir project that I never saw before:

alias __MODULE__

In simple terms, this aliases the module and makes it available in the namespace.

E.g.

defmodule Some.Nested.Module.Example do
  defstruct ...

  alias __MODULE__

  def some_fun do
    %Example{...}
  end
...
end

Here, have a slice of pizza 🍕