Skip to content

Instantly share code, notes, and snippets.

@bsbodden
Created March 11, 2010 22:36
Show Gist options
  • Save bsbodden/329768 to your computer and use it in GitHub Desktop.
Save bsbodden/329768 to your computer and use it in GitHub Desktop.
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