Ok, I tried to delete lines that contain -- from a file. The file looks like this:
-----------------------------------------------------------------
Lorem ip
As others said, you can do it with grep, but if you want to do it completely in Ruby, then look at this question, the first answer should help you.
So whats going on?
Something like this:
line = "-----------------------------------\n"
=> "-----------------------------------\n"
a = line
=> "-----------------------------------\n"
line.delete a
ArgumentError: invalid range "--
" in string transliteration
The error raised by the delete
method is because dashes are used for special character-range syntax:
"hellob".delete "a-e"
=> "hllo"
Probably you want to be taking a different approach to solve your goal, but it is difficult to tell what you want, as you don't show what you want to do with the data once lines are removed. Simply processing the line
variable just means you have an altered String
at that point.