txt: ## augment.md
  augment
  
  Combined from primary sources listed below.
  
  # [In Variables](#___top "go to top of document")[§](#(Variables)_declarator_augment "direct link")
  
  See primary documentation
  [in context](/language/variables#The_augment_declarator)
  for **The augment declarator**.
  
  With `augment`, you can add methods, but not attributes, to existing classes and grammars, provided you activated the `MONKEY-TYPING` pragma first.
  
  Since classes are usually `our` scoped, and thus global, this means modifying global state, which is strongly discouraged. For almost all situations, there are better solutions.
  
  ```raku
  # don't do this
  use MONKEY-TYPING;
  augment class Int {
      method is-answer { self == 42 }
  }
  say 42.is-answer;       # OUTPUT: «True␤»
  ```
  
  (In this case, the better solution would be to use a [function](/language/functions)).
  
  For a better, and safer example, this is a practical way to create a class module to extend [`IO::Path`](/type/IO/Path) by adding a currently missing method to yield the part of the `basename` left after the `extension` is removed. (Note there is no clear developer consensus about what to call that part or even how it should be constructed.)
  
  ```raku
  unit class IO::Barename is IO::Path;
  
  method new(|c) {
      return self.IO::Path::new(|c);
  }
  
  use MONKEY-TYPING;
  augment class IO::Path {
      method barename {
          self.extension("").basename;
      }
  }
  
  ```
  