Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Oct 23rd, 2012  |  syntax: None  |  size: 0.36 KB  |  views: 195  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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}"}