Skip to content

Commit 6fd14c7

Browse files
authored
Document attribute aliases
Part of the spec in Roast S12-class/attributes.t https://github.com/Raku/roast/blob/master/S12-class/attributes.t#L23-L33
1 parent fbf0245 commit 6fd14c7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

doc/Language/objects.pod6

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,24 @@ class Journey {
184184
}
185185
=end code
186186
187+
Alternatively, you can omit the twigil, which will still create the private
188+
attribute (with a C<!> twigil), and will also create an alias that binds
189+
the name (without the twigil) to that attribute. Thus, you can declare the
190+
same class above with
191+
192+
=begin code
193+
class Journey {
194+
has $origin;
195+
has $destination;
196+
has @travelers;
197+
has $notes;
198+
}
199+
=end code
200+
201+
If you declare the class like this, you can subsequently access the attributes
202+
either with or without the twigil – e.g., C<$!origin> and C<$origin> refer to
203+
same attribute.
204+
187205
While there is no such thing as a public (or even protected) attribute,
188206
there is a way to have accessor methods generated automatically: replace the
189207
C<!> twigil with the C<.> twigil (the C<.> should remind you of a method

0 commit comments

Comments
 (0)