txt: ## classtut.md
  ## Chunk 2 of 2
   {
      has @.utensils  is rw;
      has @.cookbooks is rw;
  
      method cook( $food ) {
          return "Cooking $food";
      }
  
      method clean_utensils {
          return "Cleaning $_" for @.utensils;
      }
  
      multi method gist(Cook:U:) { '⚗' ~ self.^name ~ '⚗' }
      multi method gist(Cook:D:) {
          '⚗ Cooks with ' ~ @.utensils.join( " ‣ ") ~ ' using '
            ~ @.cookbooks.map( "«" ~ * ~ "»").join( " and ") }
  }
  
  my $cook = Cook.new(
      utensils => <spoon ladle knife pan>,
      cookbooks => ['Cooking for geeks','The French Chef Cookbook']);
  
  say Cook.gist; # OUTPUT: «⚗Cook⚗»
  say $cook.gist; # OUTPUT: «⚗ Cooks with spoon ‣ ladle ‣ knife ‣ pan using «Cooking for geeks» and «The French Chef Cookbook»␤»
  
  ```
  
  Usually you will want to define two methods, one for the class and another for class instances; in this case, the class method uses the alembic symbol, and the instance method, defined below it, aggregates the data we have on the cook to show it in a narrative way.
  
  ## [A practical introspection example](#Classes_and_objects "go to top of document")[§](#A_practical_introspection_example "direct link")
  
  When one creates a new class, it is sometimes useful to have informative (and safe) introspection accessible more easily as a public method. For example, the following class is used to hold attributes for a record row in a CSV spreadsheet with a header row defining its field (attribute) names.
  
  ```raku
  unit class CSV-Record;
  #| Field names and values for a CSV row
  has $last;
  has $first;
  #...more fields (attributes)...
  
  method fields(--> List) {
      #| Return a list of the the attribute names (fields)
      #| of the class instance
      my @attributes = self.^attributes;
      my @names;
      for @attributes -> $a {
          my $name = $a.name;
          # The name is prefixed by its sigil and twigil
          # which we don't want
          $name ~~ s/\S\S//;
          @names.push: $name;
      }
      @names
  }
  
  method values(--> List) {
      #| Return a list of the values for the attributes
      #| of the class instance
      my @attributes = self.^attributes;
      my @values;
      for @attributes -> $a {
          # Syntax is not obvious
          my $value = $a.get_value: self;
          @values.push: $value;
      }
      @values
  }
  
  ```
  
  We use it with a simple CSV file with contents:
  
  ｢csv｣ without highlighting
  
  ```
  
  
  ```
  
  last,   first #...more fields...
  Wall,   Larry
  Conway, Damian
  
  
  ```
  
  
  ```
  
  Load the first record and show its contents:
  
  ```raku
  my $record = CSV-Record.new: :$last, :$first;
  say $record.fields.raku; # OUTPUT: «["last", "first"]␤»
  say $record.values.raku; # OUTPUT: «["Wall", "Larry"]␤»
  
  ```
  
  Note that practically we would have designed the class so that it has the `fields` list as a constant since its values are the same for all class objects:
  
  ```raku
  constant @fields = <last first>;
  method fields(--> List) {
      @fields
  }
  
  ```
  
  Downsides of using the introspective method for attribute names include slightly more processing time and power and the probable need to remove the sigil and twigil for public presentation.
  
  1 [[↑]](#fnret1) For example, closures cannot easily be reproduced this way; if you don't know what a closure is don't worry. Also current implementations have problems with dumping cyclic data structures this way, but they are expected to be handled correctly by `.raku` at some point.
  