I used a heredoc to make some simple sample data like:
> str = <<TEXT
abc^M^M^M
def^M^M^M^M
TEXT
Now look at the contents of this string:
> p str
"abc\r\r\ndef\r\r\r\n"
Note the three carriage-returns become two "\r"
s and the four carriage-returns become three "\r"
s. I've also tried the %q()
syntax with the same result. Putting the same data in a file and reading it results in a correct string with the right number of "\r"
s.
Maybe the issue is related to "How can I preserve / maintain consecutive newlines in Ruby here-document?".
P.S.: This happens both running the script in a file, and in irb
, using Ruby 1.8.7-p371, 1.9.3-p392, and 2.0.0-p247.