Methods by type

Universal methods

Full

Methods every value has — .raku, .clone, .Bool, and callable arity.

A handful of methods come from the root type Mu, so every value has them: .raku for a code representation, .clone for a copy, .Bool for truthiness, and introspection like .arity on callables.

.raku — code representation #

.raku returns a string of Raku code that would reconstruct the value — the exact, unrounded view (as opposed to the human .gist that say uses).

say [1, 2, 3].raku;
say (a => 1).raku;
say "hi".raku;
Output
[1, 2, 3]
:a(1)
"hi"

.clone — a shallow copy #

.clone copies an object, optionally overriding attributes. The copy is independent.

class P { has $.x is rw }
my $p = P.new(x => 1);
my $q = $p.clone;
$q.x = 2;
say $p.x;
say $q.x;
Output
1
2

.Bool — truthiness #

Every value defines .Bool; empty collections are false.

say [1, 2, 3].Bool;
say [].Bool;
say {}.Bool;
Output
True
False
False

Callable introspection — arity & count #

A sub or block reports its required parameter count (.arity) and its maximum (.count, including optionals).

sub f($x, $y, $z?) {}
say &f.arity;
say &f.count;
Output
2
3

Notes #