title: Ruby: replace in string ampersand to backslash with ampersand
body: <p>Simple question, but I can't find simple answer</p>
  
  <p>I have a string</p>
  
  <pre class="lang-rb prettyprint-override"><code>str = 'a&amp;b' 
  </code></pre>
  
  <p>I need to replace &amp; to \&amp;</p>
  
  <pre class="lang-rb prettyprint-override"><code>str
  &gt;&gt;&gt; a\&amp;b
  </code></pre>
  
  <p>In php I can do it like this</p>
  
  <pre class="lang-php prettyprint-override"><code>str_replace('&amp;', '\\&amp;', $str); \\ &gt;&gt;&gt; a\&amp;b
  </code></pre>
  
  <p>But in ruby this not working</p>
  
  <pre class="lang-rb prettyprint-override"><code>str.gsub('&amp;', '\\&amp;')
  &gt;&gt;&gt; a&amp;b
  </code></pre>