method fmt

Documentation for method fmt assembled from the following types:

class Cool

From Cool

(Cool) method fmt

Defined as:

method fmt($format = '%s' --> Str:D)

Uses $format to return a formatted representation of the invocant.

For more information about formats strings, see sprintf.

say 11.fmt('This Int equals %03d');               # OUTPUT: «This Int equals 011␤» 
say '16'.fmt('Hexadecimal %x');                   # OUTPUT: «Hexadecimal 10␤» 

class List

From List

(List) method fmt

Defined as:

method fmt($format = '%s'$separator = ' ' --> Str:D)

Returns a string where each element in the list has been formatted according to $format and where each element is separated by $separator.

For more information about formats strings, see sprintf.

my @a = 8..11;
say @a.fmt('%03d'',');  # OUTPUT: «008,009,010,011␤» 

class Pair

From Pair

(Pair) method fmt

Defined as:

multi method fmt(Pair:D: Str:D $format --> Str:D)

Takes a format string, and returns a string the key and value parts of the Pair formatted. Here's an example:

my $pair = :Earth(1);
say $pair.fmt("%s is %.3f AU away from the sun")
# OUTPUT: «Earth is 1.000 AU away from the sun␤» 

For more about format strings, see sprintf.