Give I have a module:
defmodule Foo do
def bar(baz) do
IO.puts baz
end
end
Is there some way that I can return:
def bar(baz) do
IO.puts baz
end
I've worked out that I can load the whole definition of module with:
Foo.__info__(:compile) |> List.last |> elem(1) |> File.read |> elem(1)
But ideally, I'd love to be about to do something like
Foo.bar/1.__definition__
#=> def bar(baz) do\n IO.puts baz\nend\d
Elixir is a compiled language. At runtime the source code is no longer there, it has been complied away to BEAM byte code. There is no source-level representation of the function at runtime for your code to inspect or retrieve.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With