6

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
Hackling
  • 113
  • 4

1 Answers1

3

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.

Scott Thompson
  • 22,629
  • 4
  • 32
  • 34