Created
December 9, 2009 18:20
-
-
Save TwP/252651 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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