#!/usr/bin/ruby # File: scrub_2.rb # Takes input from user and checks it against file of stop words. # => This version ONLY prints stopwords and * for everything else. filename = "small_stopwords.txt" if File.exists?(filename) then infile = File.open("#{filename}", "r") else puts "#{filename} not found" exit end #put the stopwords into a hash: good_hash = {} infile.each do |word| word.chomp! good_hash[word]=" " end =begin good_hash.each do |k,v| puts k end puts puts "enter a word" word = gets.chomp puts word if good_hash.key?(word) puts "yes" else puts "no" end =end puts "Enter something to scrub:" unscrubbed = gets.chomp! word_array = unscrubbed.split word_array.each do |word| if good_hash.key?("#{word}") print word + " " else print "* " end end puts exit