Sha256: a101153c22826b93e1fdaaef1e9a7c5e6348305f5ccca4f0654aed4208f87ec3

Contents?: true

Size: 931 Bytes

Versions: 14

Compression:

Stored size: 931 Bytes

Contents

require 'active_support/core_ext/module/anonymous'
require 'active_support/core_ext/module/reachable'

class Class
  begin
    ObjectSpace.each_object(Class.new) {}

    def descendants # :nodoc:
      descendants = []
      ObjectSpace.each_object(singleton_class) do |k|
        descendants.unshift k unless k == self
      end
      descendants
    end
  rescue StandardError # JRuby
    def descendants # :nodoc:
      descendants = []
      ObjectSpace.each_object(Class) do |k|
        descendants.unshift k if k < self
      end
      descendants.uniq!
      descendants
    end
  end

  # Returns an array with the direct children of +self+.
  #
  #   class Foo; end
  #   class Bar < Foo; end
  #   class Baz < Bar; end
  #
  #   Foo.subclasses # => [Bar]
  def subclasses
    subclasses, chain = [], descendants
    chain.each do |k|
      subclasses << k unless chain.any? { |c| c > k }
    end
    subclasses
  end
end

Version data entries

14 entries across 14 versions & 3 rubygems

Version Path
activesupport-4.2.11.3 lib/active_support/core_ext/class/subclasses.rb
activesupport-4.2.11.2 lib/active_support/core_ext/class/subclasses.rb
cocoapods-dependency-html-0.0.2 vendor/bundle/gems/activesupport-4.2.11.1/lib/active_support/core_ext/class/subclasses.rb
cocoapods-dependency-html-0.0.1 vendor/bundle/gems/activesupport-4.2.11.1/lib/active_support/core_ext/class/subclasses.rb
activesupport-4.2.11.1 lib/active_support/core_ext/class/subclasses.rb
activesupport-4.2.11 lib/active_support/core_ext/class/subclasses.rb
activesupport-4.2.10 lib/active_support/core_ext/class/subclasses.rb
activesupport-4.2.10.rc1 lib/active_support/core_ext/class/subclasses.rb
activesupport-4.2.9 lib/active_support/core_ext/class/subclasses.rb
activesupport-4.2.9.rc2 lib/active_support/core_ext/class/subclasses.rb
activesupport-4.2.9.rc1 lib/active_support/core_ext/class/subclasses.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/activesupport-4.2.8/lib/active_support/core_ext/class/subclasses.rb
activesupport-4.2.8 lib/active_support/core_ext/class/subclasses.rb
activesupport-4.2.8.rc1 lib/active_support/core_ext/class/subclasses.rb