I've a simple macro that injects a function into the calling module.
defmodule MyModule do
defmacro __using__(_opts) do
quote do
def run do
IO.puts "Hello world"
end
end
end
end
This works as intended but because of the fact that the run function is nested inside the quote block, I'm unable to add documentation using ExDoc. I also want to define the run function outside as I feel that makes the code look better. Something like this:
defmodule MyModule do
def run do
IO.puts "Hello world"
end
defmacro __using__(_opts) do
quote do
# Some code to inject the run function
end
end
end
How do I go about doing this? In addition, how do I add documentation using ExDoc for a nested function?
MyModule.runor do you want it to appear in therunfunction you inject into the module that doesuse MyModule?use MyModule