Guest User

Untitled

a guest
Apr 19th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. # Produces a unique word list of a text file
  2.  
  3. unless ARGV[0]
  4. puts "USAGE: ruby unique_words.rb <<text file>>"
  5. exit 1
  6. end
  7.  
  8. file = File.new( File.expand_path( ARGV[0] ) )
  9. @words = []
  10.  
  11. file.readlines.join.split.each do |word|
  12. @words << word.gsub(/[^\w]/, "")
  13. end
  14.  
  15. puts @words.uniq!, "" if ARGV[1]
  16.  
  17. puts "#{@words.length} unique words in #{file.path.split("/").last}"
Add Comment
Please, Sign In to add comment