Skip to content

Commit 2938da9

Browse files
committed
Document the augment declarator
1 parent 5be43cf commit 2938da9

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib/Language/variables.pod

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,22 @@ but still aren't installed in a scope:
445445
446446
=head2 The C<augment> Declarator
447447
448-
=comment TODO
448+
With C<augment>, you can add attributes and methods to existing classes and
449+
grammars, provided you activated the C<MONKEY-TYPING> pragma first.
450+
451+
Since classes are usually C<our> scoped, and thus global, this means modifying
452+
global state, which is strongly discouraged. For almost all situations, there
453+
are better soluations.
454+
455+
# don't do this
456+
use MONKEY-TYPING;
457+
augment class Int {
458+
method is-answer { self == 42 }
459+
}
460+
say 42.is-answer; # True
461+
462+
(In this case, the better solution would be to use a
463+
L<function|/language/functions>).
449464
450465
=head2 The C<supersede> Declarator
451466

0 commit comments

Comments
 (0)