Skip to content

Commit

Permalink
Add use + var info to readme. Closes #65
Browse files Browse the repository at this point in the history
  • Loading branch information
novaugust committed Jan 30, 2024
1 parent 405f299 commit 6fbaa8e
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,13 @@ For example, given the following broken code after an initial `mix format`:
```elixir
defmodule MyGreatLibrary do
@moduledoc make_pretty_docs(@library_options)
use OptionsMagic, my_opts: @library_options

@library_options [ ... ]
end
```

You can fix the code by moving the static value outside of the module into a naked variable and then reference it in the module.
You can fix the code by moving the static value outside of the module into a naked variable and then reference it in the module. (Note that `use` macros need an `unquote` wrapping the variable!)

Yes, this is a thing you can do in a `.ex` file =)

Expand All @@ -166,6 +167,7 @@ library_options = [ ... ]

defmodule MyGreatLibrary do
@moduledoc make_pretty_docs(library_options)
use OptionsMagic, my_opts: unquote(library_options)

@library_options library_options
end
Expand Down

0 comments on commit 6fbaa8e

Please sign in to comment.