Skip to content

Commit 848a53d

Browse files
committed
tell that the invocant defaults to self and how to call a free floating
method
1 parent e71be07 commit 848a53d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

doc/Type/Method.pod6

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ definition|/language/typesystem#Methods>, use the declarators C<my> and C<method
1717
<a b c>.&(my method (List:D:){dd self; self}).say;
1818
# OUTPUT«("a", "b", "c")␤(a b c)␤»
1919
20+
The invocant of a method defaults to C<self>. A type constraint including a
21+
type-smily can be used and is honored both for methods defined in a class and
22+
for free floating methods. Call the latter with C<.&> on an object.
23+
24+
my method m(Int:D: $b){
25+
say self.^name
26+
}
27+
my $i = 1;
28+
$i.&m(<a>);
29+
# OUTPUT«Int␤»
30+
2031
Methods will ignore extra named arguments where other types of C<Routine> will
2132
throw at runtime. Extra arguments will be forwarded by C<nextsame> and friends.
2233

0 commit comments

Comments
 (0)