Is it possible to document modules defined at runtime?

I am defining a module at runtime with Module.create/3. I am looking for a way to document the module and functions in the module so that the documentation can be retrieved for example in iex with the h function.

Simply adding @doc "my nice documentation" in the quoted expression passed to Module.create/3 does not do the trick, h my_function in iex returns " was not compiled with docs".

Is there a way to document a module created at runtime?

There‘s not. Documentation is read from the beam files of compiled modules. Runtime defined modules do not have corresponding beam files.

Would it be possible to write the module to a beam file at runtime?

I also wondered if it is possible to write doc chunks explicitly to doc/chunks/<my_module>.chunk so solve the problem. If I understand [Eep 0048 - Erlang/OTP](https://EEP 48: Documentation storage and format) correctly this should be picked up if there is no documentation in the beam file. But I did not find anything on producing these doc chunks from Elixir. Does anyone know more about this?

I’d expect that an external chunk file is allowed for third party tooling to also be able to supply documentation. This is still not a great solution for in memory modules given it would also need cleaning up.

If I am redefining a pre-existing module (i.e. a module with a compiled beam file) the documentation of that compiled file is shown for the re-defined module. This way it is possible to provide “default” documentation. Feels pretty hacky though.