Sha256: 8aa89bc9fbe6c7b0613372942475de6970f753e5cecb58b61c66f314e62f0e5d

Contents?: true

Size: 719 Bytes

Versions: 6

Compression:

Stored size: 719 Bytes

Contents

class Class

  # List all descedents of this class.
  #
  #   class X ; end
  #   class A < X; end
  #   class B < X; end
  #   X.descendents  #=> [A,B]
  #
  # NOTE: This is a intesive operation. Do not
  # expect it to be super fast.
  def descendents
    subclass = []
    ObjectSpace.each_object( Class ) do |c|
      if c.ancestors.include?( self ) and self != c
        subclass << c
      end
    end
    return subclass
  end

  unless defined?(::ActiveSupport)

    # Obvious alias for descendents.
    #
    # NOTE: ActiveSupport returns string names rather
    # then actual classes, so this is excluded
    # if ActiveSupport has already been loaded.
    alias_method :subclasses, :descendents

  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
facets-2.8.0 lib/core/facets/class/descendents.rb
facets-2.7.0 lib/core/facets/class/descendents.rb
facets-2.6.0 lib/core/facets/class/descendents.rb
facets-2.5.0 lib/core/facets/class/descendents.rb
facets-2.5.1 lib/core/facets/class/descendents.rb
facets-2.5.2 lib/core/facets/class/descendents.rb