Last active
July 7, 2022 17:09
-
-
Save vKxni/2b4e45f3a993c337c422587696b935fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Main do | |
def print, do: "Hello from Main" | |
end | |
defmodule Other do | |
defdelegate hello, to: Main, as: :print | |
end | |
IO.puts(Other.hello) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here, we are delegating
Main.print
toOther.hello
.Other is the new defmodule name, while
.hello
is our function (defdelegate) name, that refers to the main Main defmodule, but uses the functionprint
(as an atom)as: :print