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
.^mroreturns the chain of types Raku searches when resolving a method.The chain follows the inheritance line one step at a time:
C, then its parentB, thenB’s parentA, and finallyAnyandMu, which every type ends with. A deeper hierarchy simply makes the list longer.