Introspecting modules at runtime 🔎

Notes

Sometimes we want to introspect things about a compiled module at runtime.

Elixir’s Module module has a lot of functionality but it’s mostly about dealing with modules during compilation time.

Provides functions to deal with modules during compilation time.

Thankfully, Elixir exposes an __info__/1 helper that’s just what we need!

The function takes a single argument to provide runtime information. Here are its possible values:

  • :attributes - a keyword list with all persisted attributes
  • :compile - a list with compiler metadata
  • :functions - a keyword list of public functions and their arities
  • :macros - a keyword list of public macros and their arities
  • :md5 - the MD5 of the module
  • :module - the module atom name
  • :struct - if the module defines a struct and if so each field in order

Want the latest Elixir Streams in your inbox?

    No spam. Unsubscribe any time.