Skip to content

Commit b302b50

Browse files
authored
Merge pull request #3192 from uzluisf/master
Mention that the colon syntax on $.foo method is now supported
2 parents 21b691c + 3a2678d commit b302b50

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

doc/Language/objects.pod6

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,14 +449,27 @@ will itemize; C<$.a> will be equivalent to C<self.a.item> or C<$(self.a)>.
449449
450450
=begin code
451451
class A {
452+
has Int @.numbers;
452453
has $.x = (1, 2, 3);
453-
method b() { .say for self.x; .say for $.x }
454+
455+
method show-diff() { .say for self.x; .say for $.x }
456+
457+
method twice { self.times: 2 }
458+
method thrice { $.times: 3 }
459+
460+
method times($val = 1) { @!numbers.map(* * $val).list }
454461
};
455-
A.new.b; # OUTPUT: «1␤2␤3␤(1 2 3)␤»
462+
463+
my $obj = A.new(numbers => [1, 2, 3]);
464+
$obj.show-diff; # OUTPUT: «1␤2␤3␤(1 2 3)␤»
465+
say $obj.twice; # OUTPUT: «(2 4 6)␤»
466+
say $obj.thrice; # OUTPUT: «(3 6 9)␤»
456467
=end code
457468
458-
The colon-syntax for method arguments is only supported for method calls
459-
using C<self>, not the shortcut.
469+
470+
The colon-syntax for method arguments is supported for method calls
471+
using either C<self> or the shortcut, as illustrated with the methods
472+
C<twice> and C<thrice> in the example above.
460473
461474
Note that if the relevant methods C<bless>, C<CREATE> of L<Mu|/type/Mu>
462475
are not overloaded, C<self> will point to the type object in those methods.

0 commit comments

Comments
 (0)