Tutorial by Examples

defmodule MyModule do @my_favorite_number 13 @use_snake_case "This is a string (use double-quotes)" end These are only accessible from within this module.
Declare: defmodule MyApp.ViaFunctions.Constants do def app_version, do: "0.0.1" def app_author, do: "Felix Orr" def app_info, do: [app_version, app_author] def bar, do: "barrific constant in function" end Consume with require: defmodule MyApp.ViaFuncti...
Declare: defmodule MyApp.ViaMacros.Constants do @moduledoc """ Apply with `use MyApp.ViaMacros.Constants, :app` or `import MyApp.ViaMacros.Constants, :app`. Each constant is private to avoid ambiguity when importing multiple modules that each have their own copies of th...

Page 1 of 1