I'm writing a method where I need to exclude lines that contain this "{" and this "}" characters. I'm using the StringScanner Class with the exists? method. The args parameter is an array of strings.
def body_content (args)
body_lines = []
args.each_with_index { |x, i|
x.reset
if !x.exist?(Regexp.new("{")) && !x.match?(Regexp.new("^ +.*"))
body_lines << "Add space at the beginning of line #{i + 1}"
elsif !x.exist?(Regexp.new("}")) && !x.match?(Regexp.new("^ +.*"))
body_lines << "Add space at the beginning of line #{i + 1}"
end
}
body_lines
end
The end result should be that my body_lines array should only include lines that do not contain { or } and that do not have space in the beginning.
I'm succeeding with my second task (adding lines that do not have space in the beginning), however, I'm not being able to exclude lines that contain the curly brackets.
Am I not seeing something?
Regexp.new(...). For instance, don't useRegexp.new("{"), instead use/{/. It reduces visual-noise.x.exist?(/}/)