Is it possible to achieve below behavior wherein one tries to change the value of a module attribute to alter the behavior of the module methods?
defmodule Adder do
@num_to_add 10
def addTo(input), do: input + @num_to_add
end
IO.inspect Adder.addTo(5) # Prints 15
Adder.num_to_add = 20
IO.inspect Adder.addTo(5) # Expect it to print 25
It throws below error
** (CompileError) hello.exs:8: cannot invoke remote function Adder.num_to_add/0 inside match
(elixir) src/elixir_clauses.erl:26: :elixir_clauses.match/3
If this is not possible (as everything in Elixir is supposed to immutable), is there any Elixir-way of achieving similar behavior.