Documentation for method readonly

Documentation for method readonly, assembled from the following types:

class Attribute

From Attribute

(Attribute) method readonly

Defined as:

method readonly(Attribute:D: --> Bool:D)

Returns True for readonly attributes, which is the default. Returns False for attributes marked as is rw.

class Library {
    has $.address# Read-only value 
    has @.new-books is rw;
}
my $addr = Library.^attributes(:local)[0];
my $new-books = Library.^attributes(:local)[1];
say $addr.readonly;      # OUTPUT: «True␤» 
say $new-books.readonly# OUTPUT: «False␤» 

class Parameter

From Parameter

(Parameter) method readonly

Defined as:

method readonly(Parameter:D: --> Bool:D)

Returns True for read-only parameters (the default).

my Signature $sig = :(Str $x is rwBool :$is-named);
say $sig.params[0].readonly;                       # OUTPUT: «False␤» 
say $sig.params[1].readonly;                       # OUTPUT: «True␤»