See Original text in context
method STORE(\values, :)
This method should only be supplied if you want to support the:
my 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.
See Original text in context
method STORE(\values, :)
This method should only be supplied if you want to support the:
my is Foo = a => 42, b => 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 Pair
s, 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.
See Original text in context
method STORE (::?CLASS: \values, :)
This method should only be supplied if you want to support this syntax:
my 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.
does Logger;my is DNA = 'GAATCC'; # OUTPUT: «❢ Initialized❢ Change value to GAATCC»say ~; # OUTPUT: «GAA|TCC»= 'ACGTCG'; # OUTPUT: «❢ Change value to ACGTCG»say ~; # OUTPUT: «ACG|TCG»
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; for instance, as in this case, we might need to initialize any injected dependency. The STORE
method should set the self
variable and return it in all cases, including when the variable has already been initialized; however, only in the first case we need to initialize the logger we are using in this example.
The presence of the INITIALIZE
flag can be also used to create immutable data structures:
my is A = 1,2,3,4;say ; # OUTPUT: «[1,2,3,4]»= 4,5,6,7; # dies: Immutable
See Original text in context
method STORE (::?CLASS: \values, :)
This method should only be supplied if you want to support the:
my is Foo = a => 42, b => 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 Pair
s, 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.