SHARE
TWEET

Untitled

a guest Oct 23rd, 2012 201 Never
  1.     require 'open-uri'
  2.    
  3.    
  4.     hash = {}
  5.     open('http://www.gutenberg.org/cache/epub/5200/pg5200.txt').read.delete("\n").delete("\r").split(/([[:space:]])|([[:punct:]])/).reject! {|n| n == ' ' || n == ''}.each {|word| hash[word] == nil ? hash.merge!({word=>0}) : hash[word] += 1}
  6.     hash.sort_by {|k,v| v}.reverse.first(10) {|k, v| puts "#{k} = #{v}"}
RAW Paste Data
Top