Module: Bridgetown::Foundation::CoreExt::Class::Descendants

Defined in:
bridgetown-foundation/lib/bridgetown/foundation/core_ext/class.rb

Instance Method Summary collapse

Instance Method Details

#descendantsObject



7
8
9
10
11
12
13
14
15
16
17
18
# File 'bridgetown-foundation/lib/bridgetown/foundation/core_ext/class.rb', line 7

def descendants
  direct_children = subclasses.select do |klass|
    next true if klass.name.nil? # anonymous class

    # We do this to weed out old classes pre-Zeitwerk reload
    klass == Kernel.const_get(klass.name)
  rescue NameError
    nil
  end

  (direct_children + direct_children.map(&:descendants)).flatten
end