Delegate v0.2.0 Delegate.Module View Source

Provides defmoduledelegate which generates delegates for all functions and macros present on the :to module. Supports :only and :except.

use Delegate.Module provides all macros (require + import)

Link to this section Summary

Functions

Creates delegates for each function on the :to module

Link to this section Types

Link to this type

defmoduledelegate_opts() View Source
defmoduledelegate_opts() ::
  {:only, [{atom(), arity()}]} | {:except, [{atom(), arity()}]}

Link to this section Functions

Link to this macro

defmoduledelegate(to, opts \\ []) View Source (macro)
defmoduledelegate(to :: module(), opts :: [defmoduledelegate_opts()]) :: term()

Creates delegates for each function on the :to module

Arguments

  • to module to delegate to and to find the list of functions and macros to delegate
  • opts is a keyword:

    • :only (optional) functions/macros that will be delegated, excluding everything else
    • :except (optional) all functions/macros will be delegated except those listed in this argument

Examples

defmodule Base do
  def hello(name) do
    "hello #{unquote(name)}"
  end

  defmacro bye() do
    quote do
      "bye"
    end
  end
end

defmodule DelegateFun do
  use Delegate.Module

  defmoduledelegate(Base)

  # Function `hello/1` and macro `bye/0` are defined in this module
end

require DelegateFun

DelegateFun.hello("Jon")
DelegateFun.bye()