title: How to get words frequency in efficient way with ruby?
body: <p>Sample input:</p>
  
  <pre><code>"I was 09809 home -- Yes! yes!  You was"
  </code></pre>
  
  <p>and output:</p>
  
  <pre><code>{ 'yes' =&gt; 2, 'was' =&gt; 2, 'i' =&gt; 1, 'home' =&gt; 1, 'you' =&gt; 1 }
  </code></pre>
  
  <p>My code that does not work:</p>
  
  <pre><code>def get_words_f(myStr)
      myStr=myStr.downcase.scan(/\w/).to_s;
      h = Hash.new(0)
      myStr.split.each do |w|
         h[w] += 1 
      end
      return h.to_a;
  end
  
  print get_words_f('I was 09809 home -- Yes! yes!  You was');
  </code></pre>