如何确定从elixir中导入了特定功能的模块 [英] How to determine from which module a specific function was imported in elixir
本文介绍了如何确定从elixir中导入了特定功能的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
通过在某个中间模块上调用 use
来包含多个外部模块时,是否有一种简单的方法来确定给定方法实际在哪个模块中定义?
When multiple external modules are included by calling use
on some intermediate module, is there an easy way to determine in which module given method is actually defined?
例如:
defmodule ModuleB do
def method_b do
end
end
defmodule ModuleA do
# imports ModuleB implicitly
use SomeModuleImportingModuleB
def method_a
# how to determine this is ModuleB.method_b?
method_b
end
end
推荐答案
我找到了一个对我有用的解决方案,方法是使用&
捕获函数,然后对其进行检查:
I found a solution that works for me, by capturing the function using &
and then inspecting it:
def method_a
IO.inspect &method_b/0
# outputs &ModuleB.method_b
method_b
end
这篇关于如何确定从elixir中导入了特定功能的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文