Skip to content

Commit b6e83d5

Browse files
committed
doc submethod BUILD
1 parent c273e33 commit b6e83d5

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

doc/Language/typesystem.pod6

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,29 @@ such they can not be altered from outside the class they are defined in.
4242
4343
=head3 Methods
4444
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+
4568
=head4 Fallback method
4669
X<|FALLBACK (method)>
4770

0 commit comments

Comments
 (0)