11# frozen_string_literal: true
2- #
2+
33module DeadEnd
44 # This class is useful for exploring contents before and after
55 # a block
@@ -28,7 +28,7 @@ module DeadEnd
2828 #
2929 # To grab the next surrounding indentation use AroundBlockScan#scan_adjacent_indent
3030 class AroundBlockScan
31- def initialize ( code_lines : , block :)
31+ def initialize ( code_lines :, block :)
3232 @code_lines = code_lines
3333 @orig_before_index = block . lines . first . index
3434 @orig_after_index = block . lines . last . index
@@ -56,7 +56,7 @@ def scan_while(&block)
5656 end_count = 0
5757 @before_index = before_lines . reverse_each . take_while do |line |
5858 next false if stop_next
59- next true if @skip_array . detect { |meth | line . send ( meth ) }
59+ next true if @skip_array . detect { |meth | line . send ( meth ) }
6060
6161 kw_count += 1 if line . is_kw?
6262 end_count += 1 if line . is_end?
@@ -65,14 +65,14 @@ def scan_while(&block)
6565 end
6666
6767 block . call ( line )
68- end . reverse . first &.index
68+ end . last &.index
6969
7070 stop_next = false
7171 kw_count = 0
7272 end_count = 0
7373 @after_index = after_lines . take_while do |line |
7474 next false if stop_next
75- next true if @skip_array . detect { |meth | line . send ( meth ) }
75+ next true if @skip_array . detect { |meth | line . send ( meth ) }
7676
7777 kw_count += 1 if line . is_kw?
7878 end_count += 1 if line . is_end?
@@ -89,7 +89,7 @@ def capture_neighbor_context
8989 lines = [ ]
9090 kw_count = 0
9191 end_count = 0
92- before_lines . reverse . each do |line |
92+ before_lines . reverse_each do |line |
9393 next if line . empty?
9494 break if line . indent < @orig_indent
9595 next if line . indent != @orig_indent
@@ -124,14 +124,14 @@ def capture_neighbor_context
124124
125125 lines << line
126126 end
127- lines . select! { |line | !line . is_comment? }
127+ lines . select! { |line | !line . is_comment? }
128128
129129 lines
130130 end
131131
132132 def on_falling_indent
133133 last_indent = @orig_indent
134- before_lines . reverse . each do |line |
134+ before_lines . reverse_each do |line |
135135 next if line . empty?
136136 if line . indent < last_indent
137137 yield line
@@ -150,7 +150,7 @@ def on_falling_indent
150150 end
151151
152152 def scan_neighbors
153- self . scan_while { |line | line . not_empty? && line . indent >= @orig_indent }
153+ scan_while { |line | line . not_empty? && line . indent >= @orig_indent }
154154 end
155155
156156 def next_up
@@ -167,13 +167,14 @@ def scan_adjacent_indent
167167 before_after_indent << ( next_down &.indent || 0 )
168168
169169 indent = before_after_indent . min
170- self . scan_while { |line | line . not_empty? && line . indent >= indent }
170+ scan_while { |line | line . not_empty? && line . indent >= indent }
171171
172172 self
173173 end
174174
175175 def start_at_next_line
176- before_index ; after_index
176+ before_index
177+ after_index
177178 @before_index -= 1
178179 @after_index += 1
179180 self
@@ -196,7 +197,7 @@ def after_index
196197 end
197198
198199 private def after_lines
199- @code_lines [ after_index . next ..- 1 ] || [ ]
200+ @code_lines [ after_index . next ..] || [ ]
200201 end
201202 end
202203end
0 commit comments