Course of Raku / Objects, I/O, and exceptions / Classes and objects / The metaobject protocol 🆕 / Exercises / The method resolution order

Solution: The method resolution order

Here is a possible solution to the task.

Code

class A {
}

class B is A {
}

class C is B {
}

say C.^mro.map(*.^name);

🦋 You can find the source code in the file the-mro.raku.

Output

(C B A Any Mu)

Comments

  1. .^mro returns the chain of types Raku searches when resolving a method.

  2. The chain follows the inheritance line one step at a time: C, then its parent B, then B’s parent A, and finally Any and Mu, which every type ends with. A deeper hierarchy simply makes the list longer.

Course navigation

The method resolution order   |   A diamond of classes