You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/Language/objects.pod6
+21-17Lines changed: 21 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -50,12 +50,12 @@ my @words = "Abe", "Lincoln";
50
50
say @words;
51
51
# OUTPUT: «[Abe Lincoln said (Fourscore and seven years ago)]»
52
52
53
-
Multiple arguments can be specified by separating the argument list with
54
-
a colon:
53
+
Similarly, multiple arguments can be specified by placing a colon after
54
+
the method and separating the argument list with a comma:
55
55
56
56
=forcode :preamble<my @words;>
57
-
say @words.join: '--';
58
-
# OUTPUT: «Abe--Lincoln--said--Fourscore and seven years ago»
57
+
say @words.join('--').subst: 'years', 'DAYS';
58
+
# OUTPUT: «Abe--Lincoln--said--Fourscore and seven DAYS ago»
59
59
60
60
Since you have to put a C<:> after the method if you want to pass
61
61
arguments without parentheses, a method call without a colon or
@@ -144,10 +144,12 @@ another class.
144
144
=head2Attributes
145
145
X<|Attribute>X<|Property>X<|Member>X<|Slot>
146
146
147
-
Attributes are variables that exist per instance of a class; when instantiated to a value, the association between the variable and its value is called a property. They are where
148
-
the state of an object is stored. In Perl 6, all attributes are I<private>,
149
-
that means they can be accessed directly only by the class instance itself.
150
-
They are typically declared using the C<has> declarator and the C<!> twigil.
147
+
Attributes are variables that exist per instance of a class; when instantiated
148
+
to a value, the association between the variable and its value is called a
149
+
property. They are where the state of an object is stored. In Perl 6, all
150
+
attributes are I<private>, that means they can be accessed directly only by
151
+
the class instance itself. They are typically declared using the C<has>
Inside a method, the term C<self> is available, which is bound to the
390
-
invocant. C<self> can be used to call further methods on the invocant,
392
+
invocant. C<self> can be used to call further methods on the invocant,
391
393
including constructors:
392
394
393
395
class Box {
@@ -532,7 +534,8 @@ Objects are generally created through method calls, either on the type
532
534
object or on another object of the same type.
533
535
534
536
Class L<Mu> provides a constructor method called L<new>, which takes named
535
-
L<arguments|/language/functions#Arguments> and uses them to initialize public attributes.
537
+
L<arguments|/language/functions#Arguments> and uses them to initialize public
538
+
attributes.
536
539
537
540
class Point {
538
541
has $.x;
@@ -625,9 +628,9 @@ However this is considered poor practice, because it makes correct
625
628
initialization of objects from subclasses harder.
626
629
627
630
Another thing to note is that the name C<new> is not special in Perl 6. It is
628
-
merely a common convention, one that is followed quite thoroughly inL<most Perl 6
629
-
classes|/routine/new>. You can call C<bless> from any method at all, or use
630
-
C<CREATE> to fiddle around with low-level workings.
631
+
merely a common convention, one that is followed quite thoroughly in
632
+
L<most Perl 6 classes|/routine/new>. You can call C<bless> from any method at
633
+
all, or use C<CREATE> to fiddle around with low-level workings.
631
634
632
635
The C<TWEAK> submethod allows you to check things or modify attributes after
633
636
object construction:
@@ -845,10 +848,11 @@ So if you write:
845
848
then C<X::Ouch> will inherit directly from Exception, as we can see above
846
849
by listing its parents.
847
850
848
-
As they do not use what can properly be called inheritance, roles are not part of the class hierarchy.
849
-
Roles are listed with the C<.^roles> meta-method instead, which uses C<transitive> as flag for including all levels or just the first one. Despite this, a
850
-
class or instance may still be tested with smartmatches or type constraints
851
-
to see if it does a role.
851
+
As they do not use what can properly be called inheritance, roles are not part
852
+
of the class hierarchy. Roles are listed with the C<.^roles> meta-method
853
+
instead, which uses C<transitive> as flag for including all levels or just the
854
+
first one. Despite this, a class or instance may still be tested with
855
+
smartmatches or type constraints to see if it does a role.
0 commit comments