概要
paiza.ioでelixirやってみた。
Record使ってみた。
サンプルコード
require Record
Record.is_record({User, "john", 27})
|> IO.inspect
Record.is_record({})
|> IO.inspect
record = {User, "john", 27}
Record.is_record(record, User)
|> IO.inspect
defmodule User do
require Record
Record.defrecord(:user, name: "meg", age: "25")
end
defmodule Main do
import User
record = user() #=> {:user, "meg", 25}
record = user(age: 26) #=> {:user, "meg", 26}
user(record, :name) #=> "meg"
user(record, age: 26) #=> {:user, "meg", 26}
user(:name) #=> 1
user(record) #=> [name: "meg", age: 26]
record = user() #=> {:user, "meg", 25}
user(name: name) = record
name #=> "meg"
end
Record.extract(:file_info, from_lib: "kernel/include/file.hrl")
|> IO.inspect
実行結果
true
false
true
[
size: :undefined,
type: :undefined,
access: :undefined,
atime: :undefined,
mtime: :undefined,
ctime: :undefined,
mode: :undefined,
links: :undefined,
major_device: :undefined,
minor_device: :undefined,
inode: :undefined,
uid: :undefined,
gid: :undefined
]
成果物
以上。