method Str

Documentation for method Str assembled from the following types:

class Junction

From Junction

(Junction) method Str

Defined as:

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.

class RatStr

From RatStr

(RatStr) method Str

Returns the string value of the RatStr.

class Code

From Code

(Code) method Str

Defined as:

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

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

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

class Mu

From Mu

(Mu) method Str

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␤»

class Backtrace

From Backtrace

(Backtrace) method Str

Defined as:

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 =;
say $backtrace.Str;

class ComplexStr

From ComplexStr

(ComplexStr) method Str

Returns the string value of the ComplexStr.

class StrDistance

From StrDistance

(StrDistance) method Str

Defined as:

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␤» 

class IntStr

From IntStr

(IntStr) method Str

Returns the string value of the IntStr.

class Nil

From Nil

(Nil) method Str

method Str()

Warns the user that they tried to stringify a Nil.

class Thread

From Thread

(Thread) method Str

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

Returns a string which contains the invocants thread id and name.

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

class ForeignCode

From ForeignCode

(ForeignCode) method Str

method StrForeignCode:D: )

Returns the name of the code by calling name.

class Version

From Version

(Version) method Str

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

Returns a string representation of the invocant.

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

class Date

From Date

(Date) method Str

Defined as:

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'2015-12-24').Str;                     # OUTPUT: «2015-12-24␤» 
my $fmt = { sprintf "%02d/%02d/%04d" };
say'2015-12-24'formatter => $fmt).Str;  # OUTPUT: «12/24/2015␤»

role Systemic

From Systemic

(Systemic) method Str

method Str

Instance method returning the name of the object.

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

class Pair

From Pair

(Pair) method Str

Defined as:

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␤»

class DateTime

From DateTime

(DateTime) method Str

Defined as:

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.

# OUTPUT: «2015-12-24T12:23:00+02:00␤» 

class NumStr

From NumStr

(NumStr) method Str

Returns the string value of the NumStr.

class Match

From Match

(Match) method Str

Defined as:

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

Returns the matched text.

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

class List

From List

(List) method Str

Defined as:

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␤»

role Blob

From Blob

(Blob) method Str

Defined as:

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.

class IO::CatHandle

From IO::CatHandle

(IO::CatHandle) method Str

Defined as:

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

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

class IO::Special

From IO::Special

(IO::Special) method Str

method Str(IO::Special:D:)

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

class IO::Path

From IO::Path

(IO::Path) method Str

Defined as:

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 .absolute or .relative methods.

class IO::Handle

From IO::Handle

(IO::Handle) method Str

Returns the value of .path, coerced to Str.

say "foo" OUTPUT: «"foo".IO␤»