How to explicitly invoke the default implementation of a callback of a behaviour?

Hi, how can I invoke the default implementation of a callback of behaviour?

For example, if I want to override the GenServer handle_info callback, but only for some specific cases and keeping the default implementation for all other cases, what would be the proper way to do it?

Example code:

defmodule Foo do
  use GenServer

  def start_link(%State{} = state) do
    GenServer.start_link(__MODULE__, state)
  end

  def init(state) do
    {:ok, state}
  end

  def handle_info(:foo, state), do
    IO.puts("received :foo")
    {:noreply, state}
  end

  # NOTE: don't know how to do sth like this below.
  #   Needing sth like the `super` method in Python.
  # def handle_info(msg, state), do: GenServer.handle_info(msg, state)

I am working with GenServer specially, but this is a question to all elixir behaviour in general.

super(msg, state) should work - see the docs for defoverridable

3 Likes

Thanks a lot, it even named exactly as super :joy:

got lost in digging through docs.