My goal is this:
class MyBeautifulRubyClass
#some code goes here
end
puts MyBeautifulRubyClass.subclasses #returns 0
class SlightlyUglierClass < MyBeautifulRubyClass
end
puts MyBeautifulRubyClass.subclasses #returns 1
hell ideally even
puts MyBeautifulRubyClass.getSubclasses #returns [SlightlyUglierClass] in class object form
I am sure this is possible, just not sure how!
Here’s an inefficient way:
Look up all descendants of a class in Ruby
The efficient approach would use the
inheritedhook:If you need to know about descendants of descendants, you can recurse to get them: