Elixir语言中 Module.register_attribute
相关用法介绍如下。
用法:
register_attribute(module, attribute, options)
@spec register_attribute(module(), atom(), accumulate: boolean(), persist: boolean()) ::
:ok
注册一个属性。
通过注册属性,开发人员可以自定义 Elixir 存储和累积属性值的方式。
选项
注册属性时,可以给出两个选项:
-
:accumulate
- 对同一属性的多次调用将累积而不是覆盖前一个。新属性总是添加到累积列表的顶部。 -
:persist
- 该属性将以 Erlang 抽象格式保存。在与 Erlang 库交互时很有用。
默认情况下,这两个选项都是 false
。
例子
defmodule MyModule do
Module.register_attribute(__MODULE__, :custom_threshold_for_lib, accumulate: true)
@custom_threshold_for_lib 10
@custom_threshold_for_lib 20
@custom_threshold_for_lib #=> [20, 10]
end
相关用法
- Elixir Module.reserved_attributes用法及代码示例
- Elixir Module.defines?用法及代码示例
- Elixir Module.concat用法及代码示例
- Elixir Module.delete_attribute用法及代码示例
- Elixir Module.eval_quoted用法及代码示例
- Elixir Module.put_attribute用法及代码示例
- Elixir Module.split用法及代码示例
- Elixir Module.overridables_in用法及代码示例
- Elixir Module.definitions_in用法及代码示例
- Elixir Module.has_attribute?用法及代码示例
- Elixir Module.get_attribute用法及代码示例
- Elixir Module.create用法及代码示例
- Elixir Module.safe_concat用法及代码示例
- Elixir Module.attributes_in用法及代码示例
- Elixir Module用法及代码示例
- Elixir Map.keys用法及代码示例
- Elixir Map.values用法及代码示例
- Elixir Map.update用法及代码示例
- Elixir MapSet用法及代码示例
- Elixir Map.split用法及代码示例
- Elixir MapSet.intersection用法及代码示例
- Elixir Map.put_new_lazy用法及代码示例
- Elixir Map.drop用法及代码示例
- Elixir Macro.Env.fetch_alias用法及代码示例
- Elixir Map用法及代码示例
注:本文由纯净天空筛选整理自elixir-lang.org大神的英文原创作品 Module.register_attribute(module, attribute, options)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。