Sha256: c05deb0fbe02b2e7915fc497b1be842e189705840354025fd4b81929e62d8360

Contents?: true

Size: 666 Bytes

Versions: 26

Compression:

Stored size: 666 Bytes

Contents

#--
# 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

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
facets-0.9.0 lib/nano/class/descendents.rb
facets-1.0.0 lib/facet/class/descendents.rb
facets-1.0.3 packages/core/lib/facet/class/descendents.rb
facets-1.3.0 lib/facets/core/class/descendents.rb
facets-1.2.0 lib/facets/core/class/descendents.rb
facets-1.1.0 lib/facet/class/descendents.rb
facets-1.2.1 lib/facets/core/class/descendents.rb
facets-1.3.1 lib/facets/core/class/descendents.rb
facets-1.3.2 lib/facets/core/class/descendents.rb
facets-1.3.3 lib/facets/core/class/descendents.rb
facets-1.4.0 lib/facets/core/class/descendents.rb
facets-1.4.1 lib/facets/core/class/descendents.rb
facets-1.4.2 lib/facets/core/class/descendents.rb
facets-1.4.3 lib/facets/core/class/descendents.rb
facets-1.4.4 lib/facets/core/class/descendents.rb
facets-1.4.5 lib/facets/core/class/descendents.rb
facets-1.7.0 lib/facets/core/class/descendents.rb
facets-1.7.30 lib/facets/core/class/descendents.rb
facets-1.7.38 lib/facets/core/class/descendents.rb
facets-1.7.46 lib/facets/core/class/descendents.rb