【发布时间】:2015-12-17 01:32:42
【问题描述】:
如果一个模块imports 有多个其他模块,那么给定函数的来源可能并不明显。例如:
defmodule Aimable do
import Camera
import Gun
def trigger do
shoot # which import brought it in?
end
end
我知道有一些方法可以最大程度地减少这种混淆:良好的命名、专注的模块、像import Gun, only: [:shoot] 这样的定向导入等等。
但是如果我遇到这样的代码,有没有办法检查Aimable 并查看函数shoot 的起源?
【问题讨论】:
-
我来自 Ruby,
Array.instance_method(:reduce).owner返回Enumerable,这告诉我Array从哪里继承方法。
标签: elixir