Module: Byebug::Skipper::CommentLineAbove

Extended by:
CommentLineAbove
Included in:
CommentLineAbove
Defined in:
lib/byebug/skipper/comment_line_above.rb

Instance Method Summary collapse

Instance Method Details

#call(location) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/byebug/skipper/comment_line_above.rb', line 7

def call(location)
  path, _, line_no = location.rpartition(':')
  lines = File.readlines(path)

  idx = Integer(line_no) - 2
  while ignore_line?(lines[idx])
    idx -= 1
    return if idx < 0 # tried to go above the first line of the file, so abort
  end

  lines[idx] = comment_out(lines.fetch(idx))
  File.write(path, lines.join)
end