#--
# Original code from RubyOnRails (http://www.rubyonrails.com)
#++

class Class

  def descendents
    subclass = []
    ObjectSpace.each_object( Class ) do |c|
      if c.ancestors.include?( self ) and self != c
        subclass << c
      end
    end
    return subclass
  end

  alias_method :subclasses, :descendents

end


#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
=begin test

  require 'test/unit'

  class TCClass < Test::Unit::TestCase

    class A ; end
    class B < A ; end
    class C < B ; end

    def test_descendents
      assert_equal( [C,B], A.descendents )
    end

  end

=end
