Sample input:
\"I was 09809 home -- Yes! yes! You was\"
and output:
{ \'yes\' => 2, \'was\' => 2, \'i\' => 1, \'home\
This code will ask you for input and then find the word frequency for you:
puts "enter some text man"
text = gets.chomp
words = text.split(" ")
frequencies = Hash.new(0)
words.each { |word| frequencies[word.downcase] += 1 }
frequencies = frequencies.sort_by {|a, b| b}
frequencies.reverse!
frequencies.each do |word, frequency|
puts word + " " + frequency.to_s
end