Str
ErrorsCollection

Str

Synthesised documentation from type/Code type/Num type/Nil type/ForeignCode type/IO/Path type/Blob type/Match type/Label type/Mu type/Date type/Sequence type/StrDistance type/DateTime type/Thread type/Backtrace type/IO/Handle type/Systemic type/IO/Special type/Real type/Allomorph type/Pair type/IO/CatHandle type/List type/Junction type/Version

From type/Code

See Original text in context

multi method Str(Code:D: --> Str:D)

Will output the method name, but also produce a warning. Use .raku or .gist instead.

sub marine() { }
say ~&marine;
# OUTPUT: «Sub object coerced to string (please use .gist or .raku to do that)␤marine␤» 
say &marine.Str;
# OUTPUT: «Sub object coerced to string (please use .gist or .raku to do that)␤marine␤» 
say &marine.raku# OUTPUT: «sub marine { #`(Sub|94280758332168) ... }␤»

From type/Num

See Original text in context

method Str(Int:D)

Returns a string representation of the number.

say π.Str;                # OUTPUT: «3.141592653589793␤»

Cool being a parent class of Num, an explicit call to the Num.Str method is seldom needed.

say π.Str.comb == π.comb# OUTPUT: «True␤»

From type/Nil

See Original text in context

method Str()

Warns the user that they tried to stringify a Nil.

From type/ForeignCode

See Original text in context

method StrForeignCode:D: )

Returns the name of the code by calling name.

From type/IO/Path

See Original text in context

method Str(IO::Path:D: --> Str)

Alias for IO::Path.path. In particular, note that default stringification of an IO::Path does NOT use the value of $.CWD attribute. To stringify while retaining full path information use IO::Path.absolute or IO::Path.relative methods.

From type/Blob

See Original text in context

multi method Str(Blob:D:)

Throws X::Buf::AsStr with Str as payload. In order to convert to a Str you need to use .decode.

From type/Match

See Original text in context

method Str(Match:D: --> Str:D)

Returns the matched text.

"abc123def" ~~ /\d+/;
say $/.Str;               # OUTPUT: «123␤»

From type/Label

See Original text in context

Converts to a string including the name, file and line it's been defined in.

From type/Mu

See Original text in context

multi method Str(--> Str)

Returns a string representation of the invocant, intended to be machine readable. Method Str warns on type objects, and produces the empty string.

say Mu.Str;   # Use of uninitialized value of type Mu in string context. 
my @foo = [2,3,1];
say @foo.Str  # OUTPUT: «2 3 1␤»

From type/Date

See Original text in context

multi method Str(Date:D: --> Str:D)

Returns a string representation of the invocant, as specified by the formatter. If no formatter was specified, an (ISO 8601) date will be returned.

say Date.new('2015-12-24').Str;                     # OUTPUT: «2015-12-24␤» 
 
my $fmt = { sprintf "%02d/%02d/%04d".month.day.year };
say Date.new('2015-12-24'formatter => $fmt).Str;  # OUTPUT: «12/24/2015␤»

From type/Sequence

See Original text in context

multi method Str(::?CLASS:D:)

Stringifies the cached sequence.

From type/StrDistance

See Original text in context

multi method Str(StrDistance:D: --> Str)

Returns an after string value.

my $str-dist = ($str ~~ tr/old/new/);
say $str-dist.Str# OUTPUT: «fnew␤» 
say ~$str-dist;    # OUTPUT: «fnew␤» 

From type/DateTime

See Original text in context

method Str(DateTime:D: --> Str:D)

Returns a string representation of the invocant, as done by the formatter. If no formatter was specified, an ISO 8601 timestamp will be returned.

say DateTime.new('2015-12-24T12:23:00+0200').Str;
# OUTPUT: «2015-12-24T12:23:00+02:00␤» 

From type/Thread

See Original text in context

method Str(Thread:D: --> Str:D)

Returns a string which contains the invocants id and name.

my $t = Thread.new(code => { for 1..5 -> $v { say $v }}name => 'calc thread');
say $t.Str;                           # OUTPUT: «Thread<3>(calc thread)␤»

From type/Backtrace

See Original text in context

multi method Str(Backtrace:D:)

Returns a concise string representation of the backtrace, omitting routines marked as is hidden-from-backtrace, and at the discretion of the implementation, also some routines from the setting.

my $backtrace = Backtrace.new;
say $backtrace.Str;

From type/IO/Handle

See Original text in context

Returns the value of .path, coerced to Str.

say "foo".IO.open.Str# OUTPUT: «foo␤» 

From type/Systemic

See Original text in context

method Str

Instance method returning the name of the object.

say $*RAKU.Str# OUTPUT: «Raku␤»

From type/IO/Special

See Original text in context

method Str(IO::Special:D:)

This returns '<STDIN>', '<STDOUT>', or '<STDERR>' as appropriate.

From type/Real

See Original text in context

multi method Str(Real:D:)

Calls the Bridge method on the invocant and then the Str method on its return value.

From type/Allomorph

See Original text in context

method Str(Allomorph:D:)

Returns the Str value of the invocant.

From type/Pair

See Original text in context

multi method Str(Pair:D: --> Str:D)

Returns a string representation of the invocant formatted as key ~ \t ~ value.

my $b = eggs => 3;
say $b.Str;                                       # OUTPUT: «eggs  3␤»

From type/IO/CatHandle

See Original text in context

method Str(IO::CatHandle:D: --> Str:D)

Calls .Str on the currently active source handle and returns the result. If the source handle queue may get exhausted, returns an implementation-defined string ('<closed IO::CatHandle>' in Rakudo).

From type/List

See Original text in context

method Str(List:D: --> Str:D)

Stringifies the elements of the list and joins them with spaces (same as .join(' ')).

say (1,2,3,4,5).Str# OUTPUT: «1 2 3 4 5␤»

From type/Junction

See Original text in context

multi method Str(Junction:D:)

Autothreads the .Str method over its elements and returns results as a Junction. Output methods that use .Str method (print and put) are special-cased to autothread junctions, despite being able to accept a Mu type.

From type/Version

See Original text in context

method Str(Version:D: --> Str:D)

Returns a string representation of the invocant.

my $v1 = v1.0.1;
my $v2 = Version.new('1.0.1');
say $v1.Str;                                      # OUTPUT: «1.0.1␤» 
say $v2.Str;                                      # OUTPUT: «1.0.1␤»