Skip to content

[Cookbook] A Supertype Walker

ruby edited this page May 2, 2021 · 3 revisions

A small script from Ruby that walks up supertype till it’s Object. Useful for validating inheritance as an alternative to Third is Test.

class Test {}
class Other is Test {}
class Third is Other {}

var found = false
var parent = Third.supertype
while(parent != Object) {
 System.print("check %(parent)")
 if(parent == Test) found = true
 parent = parent.supertype 
}
System.print("found Test? %(found)")