We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d1c5db1 commit 7f60454Copy full SHA for 7f60454
chapter_20/macros_and_code_evalution_2.exs
@@ -0,0 +1,31 @@
1
+defmodule Times do
2
+ defmacro times_n(name_number) do
3
+ quote do:
4
+ def unquote(:"times_#{name_number}")(argument_integer), do:
5
+ unquote(name_number) * argument_integer
6
+ end
7
+end
8
+
9
+defmodule Test do
10
+ require Times
11
12
+ Times.times_n(3)
13
+ Times.times_n(4)
14
15
16
+ExUnit.start
17
18
+defmodule TimesTest do
19
+ import Times
20
+ use ExUnit.Case
21
22
+ test "times_3 called with 4 returns 12" do
23
+ expected = Test.times_3(4)
24
+ assert expected == 12
25
26
27
+ test "times_4 called with 5 returns 20" do
28
+ expected = Test.times_4(5)
29
+ assert expected == 20
30
31
0 commit comments