Course of Raku / Objects, I/O, and exceptions / Classes and objects / The metaobject protocol 🆕 / Exercises
Add a method
Problem
Define a class Dog that has only a name
attribute and no methods. Then use the MOP to add a method
speak to it at runtime. The added method should use the
object’s own name and return
<name> says woof. Create a dog named Rex
and call the new method.
Example
The program prints:
Rex says woof