Skip to content

Instantly share code, notes, and snippets.

@TwP
Created December 9, 2009 18:20
Show Gist options
  • Save TwP/252651 to your computer and use it in GitHub Desktop.
Save TwP/252651 to your computer and use it in GitHub Desktop.
# This module defines a class method called "descendants" that will return a
# list of all classes that inherit from the current class.
#
# Array.descendants
# Hash.descendants
# ActiveRecord::Base.descendants
#
module Descendants
def descendants
ary = []
ObjectSpace.each_object(self.class) {|obj| ary << obj if obj < self}
return ary
end
end
Class.class_eval 'include Descendants'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment