StrDistance objects are used to represent the return of the string transformation operator.
say (($ = "fold") ~~ tr/old/new/).^name; # OUTPUT: «StrDistance␤»
StrDistance object will stringify to the resulting string after the transformation, and will numify to the distance between the two strings.
my = "fold";my = ( ~~ tr/old/new/);say ~; # OUTPUT: «fnew␤»say +; # OUTPUT: «3␤»
This is actually a class attribute, and called as a method returns the string before the transformation:
say .before; # OUTPUT: «fold␤»
Also a class attribute, returns the string after the transformation:
say .after; # OUTPUT: «fnew␤»
before is different from
Returns the distance as a number.
multi method Int(StrDistance:)
Returns the distance between the string before and after the transformation.
multi method Str(StrDistance: --> Str)
after string value.
my = ( ~~ tr/old/new/);say .Str; # OUTPUT: «fnew␤»say ~; # OUTPUT: «fnew␤»