I’m trying to write a parser for a file format that allows backslashes
‘’ at the end of lines. The format I’m trying to parse treats
backslashes at the end of lines just like the Ruby parser would treat
them if they occured in a ruby source file.
The double quotes string constructor does what I want it to in this
irb(main):006:0> str = “line1
irb(main):007:0” still more line1
irb(main):008:0" even more line1"
=> “line1 still more line1 even more line1” <- this is exactly what I
However, if I read a string in from a file, I don’t get what I want:
$ cat testfile
still on line 1
even more line 1
irb(main):001:0> str = File.read(“testfile”)
=> “line 1 \\nstill on line 1\\neven more line 1\n”
I’d prefer not to even know about the backslashes or '\n’s, so I’d
rather have the behavior that the double quotes string constructor
=> “line1 still more line1 even more line1”
Is there any way to get this behavior when reading a file into a string?