Avoiding substitution "\\" to "\"

When a substitute a string with another string which includes the characters “\\”, these characters are reduced to “\”.

a = "Table header\n"
a << "###rows###\n"
a << "Table footer\n"

rows = "1 & 2 \\\\\\hline\n"
rows <<"3 & 4 \\\\\\hline\n"

puts rows
puts '-' * 20
puts a.gsub('###rows###', rows.chomp)

The result is:

1 & 2 \\\hline
3 & 4 \\\hline
--------------------
Table header
1 & 2 \\hline
3 & 4 \\hline
Table footer

Instead I would like to have:

Table header
1 & 2 \\\hline
3 & 4 \\\hline
Table footer

How can I avoid this?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs