Course of Raku / Objects, I/O, and exceptions / Classes and objects / The metaobject protocol 🆕 / Meta-methods
Quiz — The MOP
What does the following program print?
class Point {
has $.x;
has $.y;
}
say Point.^attributes.elems;| 0 | 1 |
| 1 | 2 |
| 0 | (Point) |
| 0 | an error |
.^attributes is a meta-method — called with
.^ on the type’s metaobject — that lists the attributes a
type declares, and .elems counts them. Point
declares two attributes, $.x and $.y, so it
prints 2.