How do we list a class’s ancestors and descendants in Crystal? I think the solution is related to Syntax to call ancestor's virtual method explicitly - #14 by RespiteSage ; which is actually made me thing of this question.
For example, for Ruby (see: Look up all descendants of a class in Ruby - Stack Overflow), we have:
class Parent
def self.descendants
ObjectSpace.each_object(Class).select { |klass| klass < self }
end
end
class Child < Parent
end
class GrandChild < Child
end
puts Parent.descendants
puts Child.descendants