Created
March 11, 2010 22:36
-
-
Save bsbodden/329768 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
class Class | |
def extends?(klass) | |
not superclass.nil? and ( superclass == klass or superclass.extends? klass ) | |
end | |
def descendants(&block) | |
Module.constants.select do |constant_name| | |
constant = eval constant_name | |
if not constant.nil? and constant.is_a? Class and constant.extends? self | |
block_given? ? (constant if block.call(constant)) : constant | |
end | |
end | |
end | |
end | |
class ActiveRecord::Base | |
def self.models | |
descendants { |c| !c.abstract_class? } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment