Module: FlatKit::DescendantTracker

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

Instance Method Summary collapse

Instance Method Details

#childrenObject



11
12
13
14
15
16
# File 'lib/flat_kit/descendant_tracker.rb', line 11

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

#find_child(method, *args) ⇒ Object

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



21
22
23
24
25
# File 'lib/flat_kit/descendant_tracker.rb', line 21

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



30
31
32
33
34
# File 'lib/flat_kit/descendant_tracker.rb', line 30

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

#inherited(klass) ⇒ Object



5
6
7
8
9
# File 'lib/flat_kit/descendant_tracker.rb', line 5

def inherited(klass)
  super
  return unless klass.instance_of?(Class)
  self.children << klass
end