This should probably be more of a comment on @Dogberts answer above, but I would post it as a separate answer for formatting.
No need to create .ex files and call the compiler on them to create bundles:
{:module, _, bytecode, _} = defmodule Elixir.Test do def t1(a), do: a def t1(a, b \\ 2), do: a + b end
Now you can have a ray file written (we saved it in the bytecode variable).
NB: beam_lib:chunks/2 works if and only the beam contains unencrypted debugging information (elixir beams are executed by default).
In addition, you do not need to write decompiled erlang code, you can simply transfer the binary directly to Elixir :
:beam_lib.chunks(bytecode, [:abstract_code])
To extract the code itself:
{:ok,{_,[abstract_code: {_, code}]}} = bytecode |> :beam_lib.chunks([:abstract_code])
code now contains code, it should be enough to learn it, but you can still use erlang assemblies:
code |> :erl_syntax.form_list
or
code |> :erl_syntax.form_list |> :erl_prettypr.format
The latter will provide you with a binary charlist containing erlang code, just like in @Dogberts answer. Use IO.puts for output.