title: How to remove all non-digits from a string in ruby?
body: <p>Users input numbers in the following forms:</p>
  
  <pre><code>1-800-432-4567
  800-432-4567
  800.432.4566
  (800)432.4567
  +1(800)-432-4567
  800 432 4567
  </code></pre>
  
  <p>I want all of these to be turned into a stripped version without the special characters like <code>18004324567</code>. The data come in the form of a <code>String</code>, so string checking isn't required.</p>
  
  <p>My method is as below:</p>
  
  <pre><code>def canonical_form number
    a = remove_whitespaces number #to clear all whitespaces in between
    a.gsub(/[()-+.]/,'')     
  end
  
  def remove_whitespaces number
    number.gsub(/\s+/,'')  #removes all whitespaces
  end
  </code></pre>
  
  <p>Is there a better way to do this? Can the white space check with the regular expression in <code>canonical_form</code> method be performed without having an extra method for white spaces? How can this be refactored or done in a neater way?</p>