From 525b89a3ec471120dd00650453796967a8a6e083 Mon Sep 17 00:00:00 2001 From: Adam Wight Date: Tue, 7 Oct 2025 22:09:32 +0200 Subject: [PATCH] Simplify dynamic method generation The Elixir side can be written using normal unquoting. --- lib/desktop/wx.ex | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/desktop/wx.ex b/lib/desktop/wx.ex index a4eebc6..db6fbf0 100644 --- a/lib/desktop/wx.ex +++ b/lib/desktop/wx.ex @@ -25,13 +25,9 @@ defmodule Desktop.Wx do """ ) - for wx_constant <- @constants do - Code.eval_quoted( - Code.string_to_quoted(""" - def wx#{wx_constant}, do: :desktop_wx.get(:wx#{wx_constant}) - """), - [], - module: __MODULE__ - ) - end + @constants + |> Enum.map(&String.to_atom("wx" <> &1)) + |> Enum.each(fn prefixed_constant -> + def unquote(prefixed_constant)(), do: :desktop_wx.get(unquote(prefixed_constant)) + end) end