Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Document behaviour of infix:<but> with non-role RHS
  • Loading branch information
zoffixznet committed Nov 27, 2016
1 parent 82f7e01 commit 9045145
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions doc/Language/operators.pod6
Expand Up @@ -1212,13 +1212,21 @@ unsuccessfully, resetting the answer to 42.
=head2 infix C«does»
=begin code :skip-test
sub infix:<does>(Mu $obj, Mu $role) is assoc<non>
sub infix:<does>(Mu $obj, Mu $role) is assoc<non>
sub infix:<does>(Mu $obj, Mu:D $obj) is assoc<non>
=end code
Mixes C<$role> into C<$obj> at run time. Requires C<$obj> to be mutable.
C<$role> doesn't need to a be a role, it can be something that knows how
to act like a role, for example enum values.
Instead of a role, you can provide an instantiated object. In this case,
the operator will create a role for you automatically. The role will contain
a single method named the same as C<$obj.^name> and that returns C<$obj>:
say 42 but 'forty two'; # 'fourty two'
my $s = 12 but class { method ^name ($) { 'warbles' } }.new;
say $s.warbles; # warbles.new
say $s + 42; # 54
=head2 infix C«but»
Expand Down

0 comments on commit 9045145

Please sign in to comment.