Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
defmodule Test do
defstruct foo: nil, bar: nil
for x <- @keys do # <-------------------------- HOW ????
def parse(unquote(x)), do: something(x)
def parse(unquote(Atom.to_string(x))), do: something(x)
end
end
@khia

This comment has been minimized.

Copy link
Owner Author

commented Jul 22, 2014

defmodule Test do
   @keys foo: nil, bar: nil
   defstruct @keys
   for {x, _} <- @keys do
     def parse(unquote(x)), do: something(unquote(x))
     def parse(unquote(Atom.to_string(x))), do: something(unquote(x))
   end
end
@khia

This comment has been minimized.

Copy link
Owner Author

commented Jul 22, 2014

defmodule Test do
    defstruct foo: nil, bar: nil
    for k <- @struct |> Map.keys |> List.delete(:__struct__) do
       def parse(unquote(x)), do: something(unquote(x))
       def parse(unquote(Atom.to_string(x))), do: something(unquote(x))
   end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.