File tree Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -449,14 +449,27 @@ will itemize; C<$.a> will be equivalent to C<self.a.item> or C<$(self.a)>.
449
449
450
450
= begin code
451
451
class A {
452
+ has Int @.numbers;
452
453
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 }
454
461
};
455
- A.new.b; # OUTPUT: «123(1 2 3)»
462
+
463
+ my $obj = A.new(numbers => [1, 2, 3]);
464
+ $obj.show-diff; # OUTPUT: «123(1 2 3)»
465
+ say $obj.twice; # OUTPUT: «(2 4 6)»
466
+ say $obj.thrice; # OUTPUT: «(3 6 9)»
456
467
= end code
457
468
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.
460
473
461
474
Note that if the relevant methods C < bless > , C < CREATE > of L < Mu|/type/Mu >
462
475
are not overloaded, C < self > will point to the type object in those methods.
You can’t perform that action at this time.
0 commit comments