Skip to content

Commit f55571a

Browse files
authored
Simplify dynamic method generation (#60)
The Elixir side can be written using normal unquoting.
1 parent 0775ffe commit f55571a

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

lib/desktop/wx.ex

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,9 @@ defmodule Desktop.Wx do
2525
"""
2626
)
2727

28-
for wx_constant <- @constants do
29-
Code.eval_quoted(
30-
Code.string_to_quoted("""
31-
def wx#{wx_constant}, do: :desktop_wx.get(:wx#{wx_constant})
32-
"""),
33-
[],
34-
module: __MODULE__
35-
)
36-
end
28+
@constants
29+
|> Enum.map(&String.to_atom("wx" <> &1))
30+
|> Enum.each(fn prefixed_constant ->
31+
def unquote(prefixed_constant)(), do: :desktop_wx.get(unquote(prefixed_constant))
32+
end)
3733
end

0 commit comments

Comments
 (0)