Say I have the definition of a function:
def rename(src, dst) do
<do rename>
end
inside of my Elixir library, can I then create within the same library:
alias rename, as: mv
so that when users can use both the rename and mv functions in my library ?
The simplest approach I can think of is via defdelegate
iex(1)> defmodule Foo do
...(1)> def foo, do: :foo
...(1)>
...(1)> defdelegate bar, to: __MODULE__, as: :foo
...(1)> end
iex(2)> Foo.foo
:foo
iex(3)> Foo.bar
:foo
Note that this defines another function bar/0
which invokes foo/0
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With