title: Ruby: iterate a String and replace characters
body: <p>I'm new to ruby and Im trying to iterate through a string to replace repeated characters with a single instance of each. I want to automate the process using an iterator so I dont have to state each character by hand. Example string:</p>
  
  <pre><code>u = %q(a a a a a b b b b c c c c)
  </code></pre>
  
  <p>I want the variable u to return String "a b c" after ensuring all repeated characters have been replaced with a single instance of each.</p>
  
  <p>I've tried</p>
  
  <pre><code>u.each.scan(/\w+/).join do |x|
  
   p u.gsub(/\x+/, x)
  
   end
  </code></pre>
  
  <p>and that wont work.How can I get around this?</p>