Elixir——模块没有用文档编译
Elixir -- Module was not compiled with docs
我昨天才开始学灵药。我有一个文件 User.exs。它看起来像这样:
defmodule User do
@moduledoc """
Defines the user struct and functions to handle users.
"""
# functions and stuff go here...
end
当我 运行 iex
时,这是我尝试查看文档时发生的情况:
iex(1)> c "user.exs"
[User]
iex(2)> h User
User was not compiled with docs
有什么想法吗?
原因是*.exs
个文件用于脚本,不会被编译,*.ex
个文件将由elixir编译。
如果您没有混合项目并且只有 user.ex
文件,那么请尝试 elixirc user.ex
并在此之后启动 iex
并键入 h User
.
如果你有一个 mix 项目然后像这样从命令行启动 iex: iex -S mix
这将加载您的项目并编译所有 *.ex
文件。现在输入 h User
.
我自己尝试了两种方法,都有效。
另请参阅:
c("user.exs")
在内存中编译文件并且不将字节码(.beam 文件)写入磁盘,而 h/1
当前需要(下面的详细信息)beam 文件存在于磁盘上才能工作.您可以让 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
h/1
依赖 Code.get_docs/2
来获取在模块上调用 :code.get_object_code/1
的文档。 :code.get_object_code/1
根据 its docs, "Searches the code path for the object code of module Module. Returns {Module, Binary, Filename}
if successful, otherwise error
."
我昨天才开始学灵药。我有一个文件 User.exs。它看起来像这样:
defmodule User do
@moduledoc """
Defines the user struct and functions to handle users.
"""
# functions and stuff go here...
end
当我 运行 iex
时,这是我尝试查看文档时发生的情况:
iex(1)> c "user.exs"
[User]
iex(2)> h User
User was not compiled with docs
有什么想法吗?
原因是*.exs
个文件用于脚本,不会被编译,*.ex
个文件将由elixir编译。
如果您没有混合项目并且只有 user.ex
文件,那么请尝试 elixirc user.ex
并在此之后启动 iex
并键入 h User
.
如果你有一个 mix 项目然后像这样从命令行启动 iex: iex -S mix
这将加载您的项目并编译所有 *.ex
文件。现在输入 h User
.
我自己尝试了两种方法,都有效。
另请参阅:
c("user.exs")
在内存中编译文件并且不将字节码(.beam 文件)写入磁盘,而 h/1
当前需要(下面的详细信息)beam 文件存在于磁盘上才能工作.您可以让 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
h/1
依赖 Code.get_docs/2
来获取在模块上调用 :code.get_object_code/1
的文档。 :code.get_object_code/1
根据 its docs, "Searches the code path for the object code of module Module. Returns {Module, Binary, Filename}
if successful, otherwise error
."