Kernel.inspect
You're seeing just the function
inspect
, go back to Kernel module for more information.
Specs
Inspects the given argument according to the Inspect
protocol.
The second argument is a keyword list with options to control
inspection.
Options
inspect/2
accepts a list of options that are internally
translated to an Inspect.Opts
struct. Check the docs for
Inspect.Opts
to see the supported options.
Examples
iex> inspect(:foo)
":foo"
iex> inspect([1, 2, 3, 4, 5], limit: 3)
"[1, 2, 3, ...]"
iex> inspect([1, 2, 3], pretty: true, width: 0)
"[1,\n 2,\n 3]"
iex> inspect("olá" <> <<0>>)
"<<111, 108, 195, 161, 0>>"
iex> inspect("olá" <> <<0>>, binaries: :as_strings)
"\"olá\\0\""
iex> inspect("olá", binaries: :as_binaries)
"<<111, 108, 195, 161>>"
iex> inspect('bar')
"'bar'"
iex> inspect([0 | 'bar'])
"[0, 98, 97, 114]"
iex> inspect(100, base: :octal)
"0o144"
iex> inspect(100, base: :hex)
"0x64"
Note that the Inspect
protocol does not necessarily return a valid
representation of an Elixir term. In such cases, the inspected result
must start with #
. For example, inspecting a function will return:
inspect(fn a, b -> a + b end)
#=> #Function<...>
The Inspect
protocol can be derived to hide certain fields
from structs, so they don't show up in logs, inspects and similar.
See the "Deriving" section of the documentation of the Inspect
protocol for more information.