Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Elixir support introspection to show available functions?

Tags:

elixir

Consider this snippet from Programming Phoenix:

defmodule Rumbl.VideoController do
  use Rumbl.Web, :controller

  def index(conn, _params) do
    videos = Repo.all(Video)
    render(conn, "index.html", videos: videos)
  end

end

index uses the render function, which it got from an import triggered by use Rumbl.Web, :controller.

I know that other functions were imported also. But does Elixir provide a way to list them?

Can I list available functions for the current scope in Elixir?

like image 803
Nathan Long Avatar asked Jan 06 '23 22:01

Nathan Long


1 Answers

You can get such information from __ENV__ macro. Documentation is present for Macro.Env struct it returns.

The most interesting fields from that struct for you would be functions and macros that contain a list of currently available functions and macros together with the module they originated from.

like image 158
michalmuskala Avatar answered May 31 '23 21:05

michalmuskala