I have two versions of __using__
, however, first version has different behaviour from one I've expected. This code does not work properly (actually, it does not import anything).
defmodule SomeModule do
defmacro __using__(opts \\ []) do
quote do
opts = unquote(opts)
if Keyword.has_key?(opts, :my_key) && opts[:my_key] == 3 do
import MyModuleOne
else
import MyModuleTwo
end
end
end
end
And this is the working version, however, I don't like having two separate quote
parts.
defmodule SomeModule do
defmacro __using__(opts \\ []) do
if Keyword.has_key?(opts, :my_key) && opts[:my_key] == 3 do
quote do
import MyModuleOne
end
else
quote do
import MyModuleTwo
end
end
end
end
How should the first one be rewritten for it to work properly?