my = method (: )"greeting".("hello"); # OUTPUT: «greeting: 'hello'␤»<a b c>.&(my method (List:) ).say;# OUTPUT: «("a", "b", "c")␤(a b c)␤»
The invocant of a method defaults to
self. A type constraint including a type-smiley can be used and is honored both for methods defined in a class and for free floating methods. Call the latter with
.& on an object.
my method m(Int: )my = 1;.(<a>);# OUTPUT: «Int␤»
Please note that the main difference between methods defined within and without a class is the need to use `&` to invoke them in the latter case. In case any other sigil is used in the definition, as in the first example, that sigil can also be used.
is actually equivalent to
Extra arguments will be forwarded by
nextsame and friends.
is AB.m( :1a, :2b );# OUTPUT: «1 named␤2 named␤»