Extend your language
1
class if2(cond1, cond2) {
2
method then(block) { # both true
3
if (cond1 && cond2) {
4
block.run;
5
}
6
return self;
7
}
8
method else1(block) { # first true
9
if (cond1 && !cond2) {
10
block.run;
11
}
12
return self;
13
}
14
method else2(block) { # second true
15
if (cond2 && !cond1) {
16
block.run;
17
}
18
return self;
19
}
20
method else(block) { # none true
21
if (!cond1 && !cond2) {
22
block.run;
23
}
24
return self;
25
}
26
}
27
28
if2(false, true).then {
29
say "if2";
30
}.else1 {
31
say "else1";
32
}.else2 {
33
say "else2"; # <- this gets printed
34
}.else {
35
say "else"
36
}
Copied!
Last modified 1yr ago
Copy link