I used this method:
matchers = {'-\n' => '', '\n' => ' ', '&' => ''}
text.gsub(/-\n|\n|&/) { |match| matchers[match] }
And gsub
substituted '\n'
with ''
, not ' '
. As there is a difference between single and double quotes regarding escape characters, I thought this will do something:
matchers = {"-\n" => '', "\n" => ' ', '&' => ''}
This in fact gave me the desired output, but I can't figure out why. It seems like '\n'
was still removed, as there were no newlines upon puts
, but it wasn't substituted. I would be grateful for an explanation.