Module: FlatKit::DescendantTracker

Included in:
Command, FieldType, Format, Input, Output
Defined in:
lib/flat_kit/descendant_tracker.rb

Overview

Internal: A module to track descendants of a class

Instance Method Summary collapse

Instance Method Details

#childrenObject



16
17
18
19
# File 'lib/flat_kit/descendant_tracker.rb', line 16

def children
  @_children = Set.new unless defined? @_children
  @_children
end

#find_child(method, *args) ⇒ Object

Find the first child that returns truthy from the given method with args



24
25
26
27
28
# File 'lib/flat_kit/descendant_tracker.rb', line 24

def find_child(method, *args)
  children.find do |child_klass|
    child_klass.send(method, *args)
  end
end

#find_children(method, *args) ⇒ Object

Find all the children that return truthy from the given method with args



33
34
35
36
37
# File 'lib/flat_kit/descendant_tracker.rb', line 33

def find_children(method, *args)
  children.select do |child_klass|
    child_klass.send(method, *args)
  end
end

#inherited(klass) ⇒ Object



9
10
11
12
13
14
# File 'lib/flat_kit/descendant_tracker.rb', line 9

def inherited(klass)
  super
  return unless klass.instance_of?(Class)

  children << klass
end