Reputation: 91895
In the Erlang shell, erl
, I can use rr(Mod)
to load the record definitions from the specified module. This allows me to see the field names when looking at a record in the shell.
What's the equivalent to rr(Mod)
in the Elixir shell, iex
?
For example, I've got an 'RSAPrivateKey'
Erlang record, but when shown in iex
, all I see is:
{:RSAPrivateKey,
<<48, 130, 4, 164, 2, 1, 0, 2, 130, 1, 1, 0, 181, 223, 0, 179, 206, 108, 57,
72, 227, 146, 53, 117, 218, 232, 204, 33, 153, 161, 201, 232, 23, 145, 201,
134, 105, 53, 164, 223, 95, 111, 64, 29, 254, 114, 146, 33, ...>>,
:not_encrypted}
Upvotes: 1
Views: 292
Reputation: 48629
You can get the field names with record_name(a_record)
:
iex(1)> c "user_record.ex"
[User]
iex(2)> import User
User
iex(3)> user1 = user()
{:user, "Meg", "25"}
iex(4)> user(user1)
[name: "Meg", age: "25"]
iex(5)> user2 = user(name: "Roger", age: 50)
{:user, "Roger", 50}
iex(6)> user(user2)
[name: "Roger", age: 50]
user_record.ex:
defmodule User do
require Record
Record.defrecord :user, [name: "Meg", age: "25"]
end
Upvotes: 1
Reputation: 121010
According to Erlang docs:
rr(Module)
Reads record definitions from a module's BEAM file. If there are no record definitions in the BEAM file, the source file is located and read instead. Returns the names of the record definitions read. Module is an atom.
That said, if the code is already compiled to BEAMs, you might use Module.record_name/0
to get an info.
If the code is not yet compiled, you still might extract the record information from erlang header file record.hrl
with Record.extract/2
.
Upvotes: 0