Elixir - 模块未使用docs编译

Mar*_*van 4 documentation elixir iex

我昨天刚开始学习长生不老药.我有一个文件User.exs.它看起来像这样:

defmodule User do
    @moduledoc """ 
    Defines the user struct and functions to handle users.
    """
    # functions and stuff go here...

end
Run Code Online (Sandbox Code Playgroud)

当我运行时iex,这是当我尝试查看文档时发生的情况:

iex(1)> c "user.exs"
[User]
iex(2)> h User
User was not compiled with docs
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

Dog*_*ert 8

c("user.exs")在内存中编译文件并且不将字节码(.beam文件)写入磁盘,而h/1当前需要(下面的详细信息)磁盘文件存在于磁盘上以便工作.您可以c将生成的字节码存储在当前目录中,以便h/1使用c("user.exs", "."):

$ ls
user.exs
$ cat user.exs
defmodule User do
  @moduledoc """
  Defines the user struct and functions to handle users.
  """
end
$ iex
Erlang/OTP 19 [erts-8.2] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Interactive Elixir (1.4.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> c("user.exs", ".")
[User]
iex(2)> h User

                                      User

Defines the user struct and functions to handle users.

iex(3)>
BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
       (v)ersion (k)ill (D)b-tables (d)istribution
^C
$ ls
Elixir.User.beam user.exs
Run Code Online (Sandbox Code Playgroud)

h/1依赖于Code.get_docs/2获取调用:code.get_object_code/1模块的文档.:code.get_object_code/1根据它的文档,"搜索模块模块的目标代码的代码路径.{Module, Binary, Filename}如果成功则返回error.否则."


gui*_*man 7

原因是*.exs文件用于编写脚本,它们不会被编译,*.ex文件将由elixir编译.

如果你没有混合项目和user.ex文件,那么尝试elixirc user.ex并在此开始后iex输入h User.

如果你有一个混合项目,那么从命令行启动iex:iex -S mix 这将加载你的项目并编译所有*.ex文件.现在输入h User.

我自己尝试了两种方式并且都工作.

也可以看看: