All learnings about "elixir"

…there are nice names for Phoenix conn status codes

In ruby there is this neat way to define response statuses, something like:

render status: :not_found

And there is something (really) similar as well within the Plug.Conn elixir package.

So in Phoenix you can do this two nice things:

send_resp(conn, 404, "Nothing found!")
send_resp(conn, :not_found, "Nothing found!")

…how to reload modules in iex

You may know about how to load files into your iex. Right?

c "my-module.exs"

If you actively work on it, and want to reload it, that you can also do this:

r MyModule

Also note that, not according to the docs, the file where this module is defined will recompiled, but only in memory. So maybe some typespecs and doc may then be outdated, since they are never loaded into memory.

…there are awesome man pages within elixir iex

One awesome discovery for me was, that you can browse the docs of commands directly from within the iex console.

Try it, within iex:

h String.Split
h Phoenix # try this with iex -S mix within a phoenix project of course

…how to call an elixir method dynamically

If you have the need to dynamically call a method in elixir, of course there is a method for that, which is called apply (apply/2, apply/3), which optionally takes a module as first parameter, and an atom as second, and a list of arguments a third.

Here are some neat examples:

apply(fn x -> x * 2 end, [2])
defmodule Test do
  def one, do: IO.puts("one")
  def two, do: IO.puts("two")
end

[:one, :two] |> Enum.each(fn method -> apply(Test, method, []) end)