Module: StateFlow::ElementVisitable

Included in:
Element, State
Defined in:
lib/state_flow/element_visitable.rb

Instance Method Summary collapse

Instance Method Details

#visit(&block) ⇒ Object

Visitorパターン



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/state_flow/element_visitable.rb', line 7

def visit(&block)
  results = block.call(self)
  (results || [:events, :guards, :action]).each do |elements_name|
    next if [:events, :guards, :action].include?(elements_name) && !respond_to?(elements_name)
    elements = send(elements_name)
    elements = [elements] unless elements.is_a?(Array)
    elements.each do |element|
      element.visit(&block) if element
    end
  end
end