Debian Codegraph @

demo/kitchen-sink/docs/raku.raku

raw
1 =begin comment
2 Raku example for ace
3 =end comment
4 class Cook is Employee {
5 has @.utensils is rw;
6 has @.cookbooks is rw;
7
8 method cook( $food ) {
9 say "Cooking $food";
10 }
11
12 method clean_utensils {
13 say "Cleaning $_" for @.utensils;
14 }
15 }
16
17 class Baker is Cook {
18 method cook( $confection ) {
19 say "Baking a tasty $confection";
20 }
21 }
22
23 my $cook = Cook.new(
24 utensils => <spoon ladle knife pan>,
25 cookbooks => 'The Joy of Cooking',
26 salary => 40000);
27
28 $cook.cook( 'pizza' ); # OUTPUT: «Cooking pizza␤»
29 say $cook.utensils.perl; # OUTPUT: «["spoon", "ladle", "knife", "pan"]␤»
30 say $cook.cookbooks.perl; # OUTPUT: «["The Joy of Cooking"]␤»
31 say $cook.salary; # OUTPUT: «40000␤»
32
33 my $baker = Baker.new(
34 utensils => 'self cleaning oven',
35 cookbooks => "The Baker's Apprentice",
36 salary => 50000);
37
38 $baker.cook('brioche'); # OUTPUT: «Baking a tasty brioche␤»
39 say $baker.utensils.perl; # OUTPUT: «["self cleaning oven"]␤»
40 say $baker.cookbooks.perl; # OUTPUT: «["The Baker's Apprentice"]␤»
41 say $baker.salary; # OUTPUT: «50000␤»