defmoduleGreeterdo@moduledoc """ ... """@doc """ Prints a hello message ## Parameters - name: String that represents the name of the person. ## Examples iex> Greeter.hello("Sean") "Hello, Sean" iex> Greeter.hello("pete") "Hello, pete" """ @spec hello(String.t()) ::String.t()defhello(name) do"Hello, "<> nameendend
如果在IEx中输入这个函数并且带有-h参数时(别忘了输入模块名),你将会看到下列结果:
iex>c("greeter.ex")[Greeter]iex> h Greeter.hellodefhello(name)Prints a hello messageParameters • name: String that represents the name of the person.Examples iex>Greeter.hello("Sean")"Hello, Sean" iex>Greeter.hello("pete")"Hello, pete"iex>
defmoduleGreeterdo@moduledoc """ This is good documentation. """end
如果你不想给模块注释,不要留空。可以考虑给模块注解提供一个值为false的参数,就像下面这样:
defmoduleGreeterdo@moduledoc falseend
当在模块里面引用一个函数时,使用单引号将其括起来:
defmoduleGreeterdo@moduledoc """ ... This module also has a `hello/1` function. """defhello(name) doIO.puts("Hello, "<> name)endend
@moduledoc下面的代码一行只写一句:
defmoduleGreeterdo@moduledoc """ ... This module also has a `hello/1` function. """aliasGoodbye.bye_bye# 就像上面这样...defhello(name) doIO.puts("Hello, "<> name)endend
使用markdown语法来编写文档。因为它能被ExDoc和IEx更好地解析:
defmoduleGreeterdo@moduledoc """ ... """@doc """ Prints a hello message ## Parameters - name: String that represents the name of the person. ## Examples iex> Greeter.hello("Sean") "Hello, Sean" iex> Greeter.hello("pete") "Hello, pete" """ @spec hello(String.t()) ::String.t()defhello(name) do"Hello, "<> nameendend