method STORE

Documentation for method STORE assembled from the following types:

language documentation Subscripts

From Subscripts

(Subscripts) method STORE

method STORE (::?CLASS:D: \values:$initialize)

This method should only be supplied if you want to support this syntax:

my @a is Foo = 1,2,3;

Which is used for binding your implementation of the Positional role.

STORE should accept the values to (re-)initialize the object with. The optional named parameter will contain a True value when the method is called on the object for the first time. It should return the invocant.

class DNA {
    has $.chain is rw;
 
    method STORE ($chain where {
                         $chain ~~ /^^ <[ACGT]>+ $$ / and
                         $chain.chars %% 3
                     }:$initialize --> DNA{
        if $initialize {
            self= DNA.newchain => $chain )
        } else {
            self.chain = $chain;
            self
        }
    }
 
    method Str(::?CLASS:D:{ return $.chain.comb.rotor(3}
};
 
my @string is DNA = 'GAATCC';
say @string.Str;    # OUTPUT: «((G A A) (T C C))␤» 
@string = 'ACGTCG';
say @string.Str;    # OUTPUT: «((A C G) (T C G))␤» 

This code takes into account the value of $initialize, which is set to True only if we are assigning a value to a variable declared using the is syntax for the first time. The STORE method should set the self variable and return it in all cases, including when the variable has already been initialized.

language documentation Subscripts

From Subscripts

(Subscripts) method STORE

method STORE (::?CLASS:D: \values:$initialize)

This method should only be supplied if you want to support the:

my %h is Foo = => 42=> 666;

syntax for binding your implementation of the Associative role.

Should accept the values to (re-)initialize the object with, which either could consist of Pairs, or separate key/value pairs. The optional named parameter will contain a True value when the method is called on the object for the first time. Should return the invocant.

role Positional

From Positional

(Positional) method STORE

method STORE(\values:$initialize)

This method should only be supplied if you want to support the:

my @a is Foo = 1,2,3;

syntax for binding your implementation of the Positional role.

Should accept the values to (re-)initialize the object with. The optional named parameter will contain a True value when the method is called on the object for the first time. Should return the invocant.

role Associative

From Associative

(Associative) method STORE

method STORE(\values:$initialize)

This method should only be supplied if you want to support the:

my %h is Foo = => 42=> 666;

syntax for binding your implementation of the Associative role.

Should accept the values to (re-)initialize the object with, which either could consist of Pairs, or separate key/value pairs. The optional named parameter will contain a True value when the method is called on the object for the first time. Should return the invocant.