Back to Library
Region:
Switch to ID
Intermediate Exercism • elixir
Module Attributes As Constants
Lesson Overview
# Introduction
About
Module attributes may be used like “constants” which are evaluated at compile-time.
defmodule Example do
@number 2
def number(), do: @number
end
However, they don’t strictly behave like constants because they can be overwritten by redefining them in the module:
defmodule Example do
@standard_message "Hello, World!"
@standard_message "Overwritten!"
def message(), do: @standard_message
end
Originally from Exercism elixir concepts