Skip to content

Instantly share code, notes, and snippets.

@rlb3
Forked from ConnorRigby/why.ex
Created April 15, 2018 20:45
Show Gist options
  • Save rlb3/7051ff901aebf5b3b93a236ba0244ee2 to your computer and use it in GitHub Desktop.
Save rlb3/7051ff901aebf5b3b93a236ba0244ee2 to your computer and use it in GitHub Desktop.
#2
defmodule :'Elixir.Why' do
@blah __ENV__.file
@file File.read!(@blah)
@num String.at(@file, 1) |> String.to_integer()
@doc false
def unquote(:"$handle_undefined_function")(function, _args) do
filename = __MODULE__.module_info()[:compile][:source] |> to_string()
File.read!(filename)
|> String.replace(":'Elixir.Why'", ":'Elixir.W"<>"hy'")
|> String.replace("# repla"<> "ceme#{@num}",
"""
\n# replaceme#{@num + 1}
def #{function}() do
#{@num}
end
""")
|> String.replace("#{@num}", "#{@num + 1}")
|> fn(code) ->
# IO.puts("\n\n\n" <> code)
File.write!(to_string(@blah), code)
code
end.()
|> Code.eval_string([], [file: filename])
|> elem(0) |> elem(1) |> apply(function, [])
end
# replaceme2
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment