4
4
5
5
= SUBTITLE Contains the result of a string transformation.
6
6
7
- C < StrDistance > objects are used to represent the return of the L < string transformation|/syntax/tr$SOLIDUS$SOLIDUS$SOLIDUS > operator.
7
+ C < StrDistance > objects are used to represent the return of the
8
+ L < string transformation|/syntax/tr$SOLIDUS$SOLIDUS$SOLIDUS > operator.
8
9
9
10
say (($ = "fold") ~~ tr/old/new/).^name; # OUTPUT: «StrDistance»
10
11
11
- A C < StrDistance > object will stringify to the resulting string after the transformation, and will numify to the distance between the two strings.
12
+ A C < StrDistance > object will stringify to the resulting string after the
13
+ transformation, and will numify to the distance between the two strings.
12
14
13
15
= begin code
14
16
my $str = "fold";
@@ -19,20 +21,37 @@ say +$str-dist; # OUTPUT: «3» │
19
21
20
22
= head1 Methods
21
23
22
- = head2 before
24
+ = head2 method before
23
25
24
- Property that returns the string before the transformation:
26
+ This is actually a class attribute, and called as a method returns the string
27
+ before the transformation:
25
28
26
29
= for code :preamble<my $str = "fold"; my $str-dist = ($str ~~ tr/old/new/); >
27
30
say $str-dist.before; #OUTPUT: «fold»
28
31
29
- = head2 after
32
+ = head2 method after
30
33
31
- Returns the string after the transformation
34
+ Also a class attribute, returns the string after the transformation
32
35
33
36
= for code :preamble<my $str = "fold"; my $str-dist = ($str ~~ tr/old/new/); >
34
37
say $str-dist.after; #OUTPUT: «fnew»
35
38
39
+ = head2 method Bool
40
+
41
+ Returns C < True > if before is different from C < After > .
42
+
43
+ = head2 method Numeric
44
+
45
+ Returns the distance as a number.
46
+
47
+ = head2 method Int
48
+
49
+ Defined as:
50
+
51
+ multi method Int(StrDistance:D:)
52
+
53
+ Returns the distance between the string before and after the transformation.
54
+
36
55
= end pod
37
56
38
57
# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6
0 commit comments