Course of Raku / Objects, I/O, and exceptions / Classes and objects / Classes / Exercises / Name the type
Solution: Name the type
Here is a possible solution to the task.
Code
class Cat {
}
class Dog {
}
my $felix = Cat.new;
say $felix.WHAT;
say $felix.WHAT === Cat.WHAT;
say $felix.WHAT === Dog.WHAT;🦋 You can find the source code in the file name-the-type.raku.
Output
(Cat)
True
FalseComments
WHATreturns the type object, shown in parentheses as(Cat)—$felixis aCat.===compares two type objects for identity.$felix.WHAT === Cat.WHATisTruebecause Felix really is aCat, while$felix.WHAT === Dog.WHATisFalse— aCatand aDogare different types, so their type objects are not the same.
Course navigation
← Name the type | Attributes →