title: Ruby string escaping, for serialization (string dumping and loading)
body: <p>I have a string which I would like to <em>serialize</em> and <em>deserialize</em>.  This one for instance:</p>
  
  <pre><code>"hello, world"
  </code></pre>
  
  <p>Now, if I find-and-replace (<strong>dump</strong> step) every <code>world</code> sub-string by <code>o</code>, this string become:</p>
  
  <pre><code>"hello, o"
  </code></pre>
  
  <p>But, if I try to find-and-replace again in the other way from <code>o</code> to <code>world</code> (<strong>load</strong> step), this string become:</p>
  
  <pre><code>"hellworld, world"
  </code></pre>
  
  <p>...which is not the same as the first string.  Is there a easy way to handle this, escaping chars, with Ruby 1.9.2?</p>
  
  <p>Thank you!</p>
  
  <p><strong>EDIT</strong>:</p>
  
  <p>In other words, I would be able to:</p>
  
  <ol>
  <li>Replace a parameter (for example "<code>world</code>") in a text by a value (for example "<code>o</code>").</li>
  <li>Replace any values ("<code>o</code>", according to the example) by the parameter ("<code>world</code>", according to the example)</li>
  </ol>
  
  <p>So I would like to be able to do so (with something like <code>dump()</code> and <code>load()</code> methods):</p>
  
  <pre><code>string = "Hello world, Ruby on Rails 3.1.0 is out! Yay!"
  serialized_string = dump(string)
      # =&gt; "Hell\o o, Ruby \on Rails 3.1.0 is \out! Yay!"
  
  load(serialized_string).should == string # =&gt; true
  </code></pre>
  
  <p>Thanks for any idea :)</p>