Skip to content

Commit 538a29e

Browse files
committed
Add documentation on @record_fields and @record_types to defrecord
1 parent 15ac6e9 commit 538a29e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

lib/elixir/lib/kernel.ex

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,6 +1405,29 @@ defmodule Kernel do
14051405
14061406
Which provides faster get and set times for record operations.
14071407
1408+
## Compile-time introspection
1409+
1410+
At the compile time, one can access following information about the record
1411+
from within the record module:
1412+
1413+
* `@record_fields` — a keyword list of record fields with defaults
1414+
* `@record_types` — a keyword list of record fields with types
1415+
1416+
defrecord Foo, bar: nil do
1417+
record_type bar: nil | integer
1418+
IO.inspect @record_fields
1419+
IO.inspect @record_types
1420+
end
1421+
1422+
prints out
1423+
1424+
[bar: nil]
1425+
[bar: {:|,[line: ...],[nil,{:integer,[line: ...],nil}]}]
1426+
1427+
where the last line is a quoted representation of
1428+
1429+
[bar: nil | integer]
1430+
14081431
## Documentation
14091432
14101433
By default records are not documented and have `@moduledoc` set to false.

0 commit comments

Comments
 (0)