A Format
is an immutable object containing the logic for converting a set of values to a string given a sprintf
compatible format specification. Acts as a standard string in every way, except that it can also be called as a Callable
with arguments to produce a string, just as sprintf
.
Available as of the 2023.06 release of the Rakudo compiler. Requires language level 6.e
.
use v6.e.PREVIEW;my = Format.new("'%5s'");say ; # OUTPUT: «'%5s'»say ("foo"); # OUTPUT: «' foo'»
Methods§
method new§
method new( --> Format)
Creates a new Format
object from a sprintf
compatible format string.
use v6.e.PREVIEW;my = Format.new("%05d");say ; # OUTPUT: «%05d»say (42); # OUTPUT: «00042»
method Callable§
method Callable(--> Callable)
Returns the Callable
that was created from the given format. Intended for introspection purposes only, as one can call the Format
object directly.
method directives§
method directives(--> List)
Returns a list of the directives seen in the given format. Intended for introspection purposes.
use v6.e.PREVIEW;my = Format.new("%05d%3x:%s");say .directives; # OUTPUT: «(d x s)»
method arity§
method arity(--> List)
Returns the minimal number of positional arguments that is needed for this format. Intended for introspection purposes.
use v6.e.PREVIEW;my = Format.new("%05d%3x:%s");say .arity; # OUTPUT: «3»
method count§
method count(--> List)
Returns the maximal number of positional arguments that is needed for this format. Intended for introspection purposes.
use v6.e.PREVIEW;my = Format.new("%05d%3x:%s");say .count; # OUTPUT: «3»