File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -49,22 +49,28 @@ Examples:
49
49
my @array = 1, 2, 3; # Array variable with three elements
50
50
my %hash = London => 'UK', Berlin => 'Germany';
51
51
52
- X < |is (container type) >
53
- The container type can be set with C < is > in a declaration.
52
+ X < |is (type of variable) >
53
+ The type to which the variable will be bound, can be set with C < is > in the
54
+ declaration of the variable. Assuming we have a C < FailHash > class:
54
55
55
56
class FailHash is Hash {
56
57
has Bool $!final = False;
57
58
multi method AT-KEY ( ::?CLASS:D: Str:D \key ){
58
59
fail X::OutOfRange.new(:what("Hash key"), :got(key), :range(self.keys)) if $!final && !self.EXISTS-KEY(key);
59
- callsame
60
+ callsame # still not final, so do normal action from Hash
60
61
}
61
62
62
63
method finalize() {
63
64
$!final = True
64
65
}
65
66
}
66
67
68
+ One can then define a C < %h > variable using C < is > :
69
+
67
70
my %h is FailHash = oranges => "round", bananas => "bendy";
71
+
72
+ And then run the following code:
73
+
68
74
say %h<oranges>;
69
75
# OUTPUT: «round»
70
76
%h.finalize;
You can’t perform that action at this time.
0 commit comments