How to have MODULE name in function docs?


I have a module that has a few public functions. In this scenario, I am trying to document the public functions, but while doing so I need to manually type the module’s name:

defmodule MyApp do

  @doc """
  This is a documention for function fun of module MyApp.
  def fun, do: nil


Normally, in code whenever I need to refer to the module I use __MODULE__. However, this wont work in documenting functions.

If I change the name of my module I want this change to be automatically reflected in the docs.


  • Is there a keyword similar to __MODULE__ for documenting functions?

You can use interpolation like in any other string in elixir:

@doc """
Something about this `#{__MODULE__}`

You can do that in your doctests too!

1 Like