Code: Select all
words = {}
File.open('file', 'r').readlines.each do |line|
line.split.each do |word|
word.gsub!(/[[:punct:]]/, '')
if words[word]==nil
words.merge!(Hash[word=>0])
else
words[word]+=1
end
end
end
puts words.sort_by {|k,v|v}.first