For note, module attributes are a lot like normal bindings, just saving you from typing the unquote part.
So this:
defmodule ModuleAttribute do
@thing 1
@thing 2
def blah(), do: @thing # returns 2
@thing 3
end
Is the same as this:
defmodule ModuleAttribute do
thing = 1
thing = 2
def blah(), do: unquote(thing) # returns 2
thing = 3
end
And thus this with an accumulated attribute:
defmodule ModuleAttribute do
Module.register_attribute(__MODULE__, :thing, accumulate: true)
@thing 1
@thing 2
def blah(), do: @thing # returns [2, 1]
@thing 3
end
Is the same as this:
defmodule ModuleAttribute do
thing = []
thing = [1 | thing]
thing = [2 | thing] # So this is now [2, 1]
def blah(), do: unquote(thing) # returns [2, 1]
thing = [3 | thing]
end


















