module Byebug::Skipper::CommentLineAbove

Public Instance Methods

call(location) click to toggle source
# 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

Private Instance Methods

comment_out(line) click to toggle source
# File lib/byebug/skipper/comment_line_above.rb, line 23
def comment_out(line)
  line.sub(/\A\s*/, '\0# ')
end
ignore_line?(line) click to toggle source
# File lib/byebug/skipper/comment_line_above.rb, line 27
def ignore_line?(line)
  line.strip.empty? || line.strip.start_with?('#')
end