Skip to content

Instantly share code, notes, and snippets.

@dwhelan
Last active December 24, 2017 05:09
Show Gist options
  • Save dwhelan/5651de36bfee7ad6c8720c981b5bfc0f to your computer and use it in GitHub Desktop.
Save dwhelan/5651de36bfee7ad6c8720c981b5bfc0f to your computer and use it in GitHub Desktop.
If you have a name with "la" in it, allows you to Elixirify your name where your name can be represented with valid pipelined Elixir functions. For example, if your name is "declan" then dec|>n returns "declan").
iex> c "lib/name.ex"
[MyName, ElixirName]
iex> MyName.is
"declan
defmodule ElixirName do
defmacro __using__(name) do
[prefix, suffix] = String.split(name, "la")
quote do
import unquote(__MODULE__)
def unquote(:"#{prefix}")(), do: unquote(prefix)
def unquote(:"#{suffix}")(x), do: "#{x}la#{unquote(suffix)}"
end
end
end
defmodule MyName do
use ElixirName, "declan"
def is do
dec|>n
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment