Split koan into two functions with different arity
This commit is contained in:
17
lib/koans.ex
17
lib/koans.ex
@@ -4,13 +4,18 @@ defmodule Koans do
|
|||||||
mangled_body = ASTMangler.expand(body, quote do: answer)
|
mangled_body = ASTMangler.expand(body, quote do: answer)
|
||||||
quote do
|
quote do
|
||||||
@koans unquote(compiled_name)
|
@koans unquote(compiled_name)
|
||||||
def unquote(compiled_name)(answer \\ :nothing) do
|
def unquote(compiled_name)() do
|
||||||
try do
|
try do
|
||||||
if answer == :nothing do
|
unquote(body)
|
||||||
unquote(body)
|
:ok
|
||||||
else
|
rescue
|
||||||
unquote(mangled_body)
|
e in _ -> e
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def unquote(compiled_name)(answer) do
|
||||||
|
try do
|
||||||
|
unquote(mangled_body)
|
||||||
:ok
|
:ok
|
||||||
rescue
|
rescue
|
||||||
e in _ -> e
|
e in _ -> e
|
||||||
|
|||||||
Reference in New Issue
Block a user