Skip to content

Instantly share code, notes, and snippets.

@khia
Created July 22, 2014 00:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khia/606c51e2c4123f2d87ef to your computer and use it in GitHub Desktop.
Save khia/606c51e2c4123f2d87ef to your computer and use it in GitHub Desktop.
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
Copy link
Author

khia 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
Copy link
Author

khia 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