Sha256: bf1d0766cdd24f4e63b59af9bbdd9b714b7088e2a1aa3e48a0bb7107fb8cc8d9

Contents?: true

Size: 602 Bytes

Versions: 21

Compression:

Stored size: 602 Bytes

Contents

# typed: strict
# frozen_string_literal: true

class Class
  extend T::Sig

  # Returns an array with all classes that are < than its receiver.
  #
  #   class C; end
  #   C.descendants # => []
  #
  #   class B < C; end
  #   C.descendants # => [B]
  #
  #   class A < B; end
  #   C.descendants # => [B, A]
  #
  #   class D < C; end
  #   C.descendants # => [B, A, D]
  sig { returns(T::Array[Class]) }
  def descendants
    result = ObjectSpace.each_object(singleton_class).reject do |k|
      T.cast(k, Module).singleton_class? || k == self
    end

    T.cast(result, T::Array[Class])
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
tapioca-0.4.27 lib/tapioca/core_ext/class.rb
tapioca-0.4.26 lib/tapioca/core_ext/class.rb
tapioca-0.4.25 lib/tapioca/core_ext/class.rb
tapioca-0.4.24 lib/tapioca/core_ext/class.rb
tapioca-0.4.23 lib/tapioca/core_ext/class.rb
tapioca-0.4.22 lib/tapioca/core_ext/class.rb
tapioca-0.4.21 lib/tapioca/core_ext/class.rb
tapioca-0.4.20 lib/tapioca/core_ext/class.rb
tapioca-0.4.19 lib/tapioca/core_ext/class.rb
tapioca-0.4.18 lib/tapioca/core_ext/class.rb
tapioca-0.4.17 lib/tapioca/core_ext/class.rb
tapioca-0.4.16 lib/tapioca/core_ext/class.rb
tapioca-0.4.15 lib/tapioca/core_ext/class.rb
tapioca-0.4.14 lib/tapioca/core_ext/class.rb
tapioca-0.4.13 lib/tapioca/core_ext/class.rb
tapioca-0.4.12 lib/tapioca/core_ext/class.rb
tapioca-0.4.11 lib/tapioca/core_ext/class.rb
tapioca-0.4.10 lib/tapioca/core_ext/class.rb
tapioca-0.4.9 lib/tapioca/core_ext/class.rb
tapioca-0.4.8 lib/tapioca/core_ext/class.rb