Course of Raku / Objects, I/O, and exceptions / Classes and objects / Introspecting objects / Exercises / Count the attributes
Solution: Count the attributes
Here is a possible solution to the task.
Code
class Point {
has $.x;
has $.y;
}
say Point.^attributes.elems;🦋 You can find the source code in the file count-attributes.raku.
Output
2Comments
.^attributesreturns the list of the class’s attributes..elemscounts them. ThePointclass declares two attributes, so the answer is2.