Elixir使用模块
示例
模块有四个相关联的关键词在其他模块中使用它们做:alias,import,use,和require。
alias将使用其他名称(通常更短)注册模块:
defmodule MyModule do # Will make this module available as `CoolFunctions` alias MyOtherModule.CoolFunctions # Or you can specify the name to use alias MyOtherModule.CoolFunctions, as: CoolFuncs end
import将使模块中的所有功能可用,而它们前面没有名称:
defmodule MyModule do
import Enum
def do_things(some_list) do
# No need for the `Enum.` prefix
join(some_list, " ")
end
enduse允许模块向当前模块中注入代码-这通常是作为框架的一部分完成的,该框架创建了自己的功能,以使您的模块确认某些行为。
require从模块加载宏,以便可以使用它们。
热门推荐
1 训练狗狗工作
4 狗狗定点排便训练
5 狗狗训练吠叫
6 狗狗尿垫训练
7 狗狗训练座
8 狗狗训练攻略
9 狗狗训练记
10 做训练狗狗
11 狗狗训练词
12 狗狗谢谢怎么训练
13 狗狗训练如厕
14 狗狗太凶怎么训练
15 狗狗训练它
16 狗狗克制训练
17 训练基地狗狗
18 怎么样训练狗狗大小硬