Advertisement
Guest User

Untitled

a guest
Aug 31st, 2015
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. defmodule Foo do
  2. defmacro import_sibling(name) do
  3. new_module = __MODULE__
  4. |> Module.split()
  5. |> List.delete_at(-1)
  6. |> List.insert_at(-1, unquote(name))
  7. |> Module.concat()
  8.  
  9. quote do
  10. import unquote(new_module)
  11. end
  12. end
  13. end
  14.  
  15. defmodule MyApp.Bar do
  16. import Foo
  17. import_sibbling(Baz)
  18. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement