gpt4 book ai didi

elixir - 我怎么能在 elixir 中看到所有模块的导入和定义函数?

转载 作者:行者123 更新时间:2023-12-04 03:15:29 24 4
gpt4 key购买 nike

我有模块

defmodule There do
import Othermodule, only: [a: 1]

def b do
end
end

我怎样才能得到函数 ab 的列表?

最佳答案

您可以使用 __ENV__ macroDogbert 提到的 Module.__info__(:functions) 相结合:

my_functions = __MODULE__.__info__(:functions)
imported_functions = __ENV__.functions
|> Enum.filter(fn {module, _functions} -> module != Kernel end)
|> Enum.map(&elem(&1, 1))
|> List.flatten

(my_functions ++ imported_functions)
|> Enum.map(&elem(&1, 0))
|> inspect
|> IO.puts

如果删除最后一个 Enum.map,您将获得 {function_name, function_arity} 的关键字列表。

关于elixir - 我怎么能在 elixir 中看到所有模块的导入和定义函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41444579/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com