Reputation: 15146
I have module
defmodule There do
import Othermodule, only: [a: 1]
def b do
end
end
How could I get the list of functions a
& b
?
Upvotes: 5
Views: 392
Reputation: 9010
You can use the __ENV__
macro combined with Module.__info__(:functions)
mentioned by Dogbert:
my_functions = __MODULE__.__info__(:functions)
imported_functions = __ENV__.functions
|> Enum.filter(fn {module, _functions} -> module != Kernel end)
|> Enum.map(&elem(&1, 1))
|> List.flatten
(my_functions ++ imported_functions)
|> Enum.map(&elem(&1, 0))
|> inspect
|> IO.puts
If you remove the last Enum.map
you'll get a Keyword List of {function_name, function_arity}
.
Upvotes: 5