【问题标题】:Get a list of all elixir modules in IEx获取 IEx 中所有 elixir 模块的列表
【发布时间】:2020-02-16 02:00:25
【问题描述】:

要获取 IEx 中模块上所有函数的列表,我可以运行:


Map.__info__(:functions)
# or
Enum.__info__(:functions)


使用{Module}.__info__(:functions) 格式。

如何获取所有标准库模块的列表?

【问题讨论】:

    标签: elixir elixir-iex


    【解决方案1】:

    在 IEx 中,您可以键入 : + Tab 以获取所有可用模块的列表。

    【讨论】:

      【解决方案2】:

      如果您想获取所有已加载的 Elixir 模块,而不需要 erlang 模块,请在干净的 IEx shell 中运行以下命令:

      :code.all_loaded() 
      |> Enum.filter(fn {mod, _} -> "#{mod}" =~ ~r{^[A-Z]} end)
      |> Enum.map(fn {mod, _} -> mod end)
      
      # [Exception, Application, Inspect.Atom, IEx.Pry, Logger.Config, Module, Keyword, ... ]
      

      这也将包括像IEx.Config 这样的子模块,但您可以使用一些额外的映射来过滤它们:

      :code.all_loaded() 
      |> Enum.filter(fn {mod, _} -> "#{mod}" =~ ~r{^[A-Z]} end)
      |> Enum.map(fn {mod, _} -> mod end)
      |> Enum.map(fn mod -> hd(Module.split(mod)) end)
      |> Enum.uniq
      
      # ["Exception", "Application", "Inspect", "IEx", "Logger", "Module", "Keyword", ... ]
      

      【讨论】:

      • 这似乎是我正在寻找的东西,但是末端有三个点,这意味着列表中还有更多内容。我如何获得整个列表?
      • IO.inspectIO.puts输出
      • :erlang.loaded() |> Enum.sort() |> inspect(limit: :infinity) |> IO.puts
      • Elixir 中没有“子模块”的概念。其实IEx.PryIEx是两个完全不同的模块,彼此一无所知。
      猜你喜欢
      • 2010-10-08
      • 1970-01-01
      • 2014-09-13
      • 2020-03-14
      • 2016-04-02
      • 1970-01-01
      • 2010-12-20
      • 2011-09-21
      相关资源
      最近更新 更多