Skip to content

Commit 9045145

Browse files
authored
Document behaviour of infix:<but> with non-role RHS
1 parent 82f7e01 commit 9045145

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

doc/Language/operators.pod6

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,13 +1212,21 @@ unsuccessfully, resetting the answer to 42.
12121212
=head2 infix C«does»
12131213
12141214
=begin code :skip-test
1215-
sub infix:<does>(Mu $obj, Mu $role) is assoc<non>
1215+
sub infix:<does>(Mu $obj, Mu $role) is assoc<non>
1216+
sub infix:<does>(Mu $obj, Mu:D $obj) is assoc<non>
12161217
=end code
12171218
12181219
Mixes C<$role> into C<$obj> at run time. Requires C<$obj> to be mutable.
12191220
1220-
C<$role> doesn't need to a be a role, it can be something that knows how
1221-
to act like a role, for example enum values.
1221+
Instead of a role, you can provide an instantiated object. In this case,
1222+
the operator will create a role for you automatically. The role will contain
1223+
a single method named the same as C<$obj.^name> and that returns C<$obj>:
1224+
1225+
say 42 but 'forty two'; # 'fourty two'
1226+
1227+
my $s = 12 but class { method ^name ($) { 'warbles' } }.new;
1228+
say $s.warbles; # warbles.new
1229+
say $s + 42; # 54
12221230
12231231
=head2 infix C«but»
12241232

0 commit comments

Comments
 (0)