routine self
1 | language documentation Terms |
1.1 | (Terms) term self |
2 | class Mu |
2.1 | (Mu) method self |
3 | class Failure |
3.1 | (Failure) method self |
Documentation for routine self
assembled from the following types:
language documentation Terms
From Terms
(Terms) term self
Inside a method, self
refers to the invocant (i.e. the object the method was called on). If used in a context where it doesn't make sense, a compile-time exception of type X::Syntax::NoSelf is thrown.
class Mu
From Mu
(Mu) method self
method self(--> Mu)
Returns the object it is called on.
class Failure
From Failure
(Failure) method self
Defined as:
method self(Failure: --> Failure)
If the invocant is a handled Failure
, returns it as is. If not handled, throws its Exception. Since Mu type provides .self
for every class, calling this method is a handy way to explosively filter out Failures:
my = '♥'.Int;# $num1 now contains a Failure object, which may not be desirablemy = '♥'.Int.self;# .self method call on Failure causes an exception to be thrownmy = '42'.Int.self;# Int type has a .self method, so here $num3 has `42` in it(my = '♥'.Int).so;say .self; # OUTPUT: «(HANDLED) Cannot convert string to number…»# Here, Failure is handled, so .self just returns it as is