Course of Raku / Advanced / More about built-in types / Enumerations 🆕 / Values and keys

Quiz — Enum values

What does the following program print?

enum Day (Mon => 1, Tue => 2);
say Tue.key;
1Tue
02
01
0Mon

.value gives the number behind a constant, but .key gives its name as a string. So Tue.key is Tue, regardless of the number 2 that was assigned to it.

Course navigation

Values and keys   |   Traffic lights