Created
December 16, 2020 02:56
-
-
Save djthread/fc396d7ae6029ddcd20372b13abf877e 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 Foo do | |
def bar do | |
:bar | |
end | |
end | |
defmodule Weird do | |
@moduledoc """ | |
Illustrates a weird behavior I noticed which doesn't seem to make sense. | |
Set `MIX_ENV` to `prod` and `mix release`. Then, try these: | |
$ _build/prod/rel/weird/bin/weird eval "Weird.a()" | |
Function is not exported! Why? :complete amazement: | |
$ _build/prod/rel/weird/bin/weird eval "Weird.b()" | |
Function is not exported! Why? :complete amazement: | |
$ _build/prod/rel/weird/bin/weird eval "Weird.c()" | |
Function is exported. | |
""" | |
# nope | |
def a do | |
if function_exported?(Foo, :bar, 0), | |
do: IO.puts("Function is exported."), | |
else: IO.puts("Function is not exported! Why? :complete amazement:") | |
end | |
# thought maybe loading the app or this might help - no dice | |
def b do | |
Application.ensure_all_started(:weird) | |
a() | |
end | |
# but after simply checking the functions on the module like this, | |
# `function_exported?/3` returns true! By looking, I've changed it; | |
# Heisenberg principle at work here! | |
def c do | |
Foo.__info__(:functions) | |
a() | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment