Elixir语言中 Module.has_attribute?
相关用法介绍如下。
用法:
has_attribute?(module, key)
(从 1.10.0 开始)
@spec has_attribute?(module(), atom()) :: boolean()
检查给定属性是否已定义。
如果属性已使用
注册或分配了值,则该属性被定义。如果使用register_attribute/3
删除了某个属性,则不再认为该属性已定义。delete_attribute/2
该函数只能在尚未编译的模块上使用。
例子
defmodule MyModule do
@value 1
Module.register_attribute(__MODULE__, :other_value)
Module.put_attribute(__MODULE__, :another_value, 1)
Module.has_attribute?(__MODULE__, :value) #=> true
Module.has_attribute?(__MODULE__, :other_value) #=> true
Module.has_attribute?(__MODULE__, :another_value) #=> true
Module.has_attribute?(__MODULE__, :undefined) #=> false
Module.delete_attribute(__MODULE__, :value)
Module.has_attribute?(__MODULE__, :value) #=> false
end
相关用法
- 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.get_attribute用法及代码示例
- Elixir Module.reserved_attributes用法及代码示例
- Elixir Module.register_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.has_attribute?(module, key)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。