美文网首页
Elixir-文档模块

Elixir-文档模块

作者: 你期待的花开 | 来源:发表于2018-11-14 17:36 被阅读12次

Elixir提供了多种方式来编写注释或者是注解。下面是其中三种方式:

  • # - 用于单行的注释
  • @moduledoc- 用于模块文档的注释
  • @doc - 用于函数的注释

模块注释

@moduledoc提供模块级别的注释。这个注解一般放在模块定义的最前面,也就是defmodule后。下面的例子简单地展示了@moduledoc这个装饰器的用法。

defmodule Greeter do
  @moduledoc """
  Provides a function `hello/1` to greet a human
  """

  def hello(name) do
    "Hello, " <> name
  end
end

用户可以在IEx里面通过h这个辅助函数看到我们在这个模块里定义的文档。

iex> c("greeter.ex")
[Greeter]

iex> h Greeter

                Greeter

Provides a function hello/1 to greet a human

函数注释

@doc这个装饰器能够提供函数级别的文档注释。@doc装饰器使用的时候只需要放在函数定义前。

defmodule Greeter do
  @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()
  def hello(name) do
    "Hello, " <> name
  end
end

相关文章

  • Elixir-文档模块

    Elixir提供了多种方式来编写注释或者是注解。下面是其中三种方式: # - 用于单行的注释 @moduledoc...

  • Elixir-模块指令

    Elixir提供了几种使用导入模块的方式,import,require,use,alias,这些都可以对模块进行应...

  • MagicMirror² 模块开发文档

    MagicMirror² 模块开发文档 对原文档的拙劣翻译 本文档介绍了开发MagicMirror²模块的方法目录...

  • 文本处理--string模块

    模块描述 简要接口文档 模块全局变量 模块函数 模块类

  • day9-作业

    模块名:homework 文本文档 调用模块 结果

  • 5.系统模块下

    日志模块logging 日志对象调用: configparser模块 生成文档模块 hashlib模块 加密相关操作

  • python 线程锁、条件变量

    相关模块:thread、threading thread 模块 thread 文档:https://docs.py...

  • ansible 15个模块

    1.1 shell shell模块: 类似command模块升级版---万能模块 官方文档:https://doc...

  • 详细设计文档

    详细设计文档包含每个模块对应的接口,数据格式,返回值。一般每个模块对应一个详细设计文档。

  • Node.js

    一、入门 1.fs模块 search node.js fs 文档(文件系统模块) 2.http模块 search ...

网友评论

      本文标题:Elixir-文档模块

      本文链接:https://www.haomeiwen.com/subject/zovqmftx.html