Delegate v0.2.0 Delegate.Function View Source

Provides defdelegateall which allows delegating to all the functions on the target module

use Delegate.Function 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

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

Link to this section Functions

Link to this macro

defdelegateall(to, opts \\ []) View Source (macro)
defdelegateall(to :: module(), opts :: [defdelegateall_opts()]) :: term()

Creates delegates for each function on the :to module

Arguments

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

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

Examples

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

  def bye() do
    "bye"
  end
end

defmodule DelegateFun do
  use Delegate.Function

  defdelegateall(Base)

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

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