File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,29 @@ such they can not be altered from outside the class they are defined in.
42
42
43
43
= head3 Methods
44
44
45
+ = head4 Submethod BUILD
46
+
47
+ The submethod C < BUILD > is called by the submethod C < BUILDALL > defined in
48
+ L < /type/Mu > , which in turn is called by C < .bless > . It is meant to set private
49
+ and public attributes of a class and receives all names attributes passed into
50
+ C < .bless > . Since it is called by C < BUILDALL > it is called by the default
51
+ constructor C < .new > defined in C < Mu > .
52
+
53
+ class C {
54
+ has $.attr;
55
+ submethod BUILD (:$attr = 42) {
56
+ $!attr = $attr
57
+ };¶
58
+ multi method new($positional) {
59
+ self.bless(:attr($positional), |%_)
60
+ }
61
+ };
62
+
63
+ C.new.say; C.new('answer').say;
64
+ # OUTPUT:
65
+ # C.new(attr => 42)
66
+ # C.new(attr => "answer")
67
+
45
68
= head4 Fallback method
46
69
X < |FALLBACK (method) >
47
70
You can’t perform that action at this time.
0 commit comments