Created
August 28, 2014 12:47
-
-
Save alco/cd7e55ac3de738bcfda9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def gen_module(file, rest_body) do | |
# load things from the file here and assign them to variables | |
Module.create(<name>, quote bind_quoted: [rest_body: rest_body, var1: var1, ...] do | |
# now unquote() can be called here freely, it will be deferred until module compilation | |
# therefore, you can copy-paste your previous in-line code without the file loading part | |
def unquote(...)(...) do | |
unquote(...) | |
end | |
... | |
rest_body | |
end) | |
end | |
# in another file else | |
gen_module("file.txt", quote do | |
def latitude do | |
:random.seed(:erlang.now) | |
((:random.uniform * 180) - 90) | |
end | |
def longitude do | |
:random.seed(:erlang.now) | |
((:random.uniform * 360) - 180) | |
end | |
def street_address(true), do: street_address <> " " <> secondary_address | |
def street_address(_), do: street_address | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment