File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
misc/perl6advent-2010/articles Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -65,3 +65,23 @@ way to match a regex, it has no special operator.
65
65
While most smart matching cases return a Bool, matching against a regex
66
66
returns a C<Match> object - which behaves appropriately in boolean context
67
67
too.
68
+
69
+ You have probably started wondering: a'right, that for built-in types,
70
+ how do I use it in my own classes? You need to write a special ACCEPTS
71
+ method for it. Say we have our good, old class Point:
72
+
73
+ class Point {
74
+ has $.x;
75
+ has $.y;
76
+ method ACCEPTS(Positional $p2) {
77
+ return $.x == $p2[0] and $.y == $p2[1]
78
+ }
79
+ }
80
+
81
+ Everything clear? Let's see how it works:
82
+
83
+ my $a = Point.new(x => 7, y => 9);
84
+ say [3, 5] ~~ $a; # Bool::False
85
+ say (7, 9) ~~ $a; # Bool::True
86
+
87
+ # Further ideas -- why not symetric?
You can’t perform that action at this time.
0 commit comments