Class: DeadEnd::UnvisitedLines

Inherits:
Object
  • Object
show all
Defined in:
lib/dead_end/unvisited_lines.rb

Overview

Tracks which lines various code blocks have expanded to and which are still unexplored

Instance Method Summary collapse

Constructor Details

#initialize(code_lines:) ⇒ UnvisitedLines

Returns a new instance of UnvisitedLines.



7
8
9
10
11
# File 'lib/dead_end/unvisited_lines.rb', line 7

def initialize(code_lines:)
  @unvisited = code_lines.sort_by(&:indent_index)
  @visited_lines = {}
  @visited_lines.compare_by_identity
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/dead_end/unvisited_lines.rb', line 13

def empty?
  @unvisited.empty?
end

#peekObject



17
18
19
# File 'lib/dead_end/unvisited_lines.rb', line 17

def peek
  @unvisited.last
end

#popObject



21
22
23
# File 'lib/dead_end/unvisited_lines.rb', line 21

def pop
  @unvisited.pop
end

#visit_block(block) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/dead_end/unvisited_lines.rb', line 25

def visit_block(block)
  block.lines.each do |line|
    next if @visited_lines[line]
    @visited_lines[line] = true
  end

  while @visited_lines[@unvisited.last]
    @unvisited.pop
  end
end