text = "la li lu la la bla bla"
words = text.split # words now is an array of the words in text

word_count = words.inject(Hash.new(0)) do |hash, word|
  hash[word] += 1
  hash
end # This creates a hash with a default value of 0, then iterates through the words array and adds 1 to hash[word] for every word in it.
#word_count now is a hash of the form {"la" => 3, "li" => 1, "bla" => 2, "lu" => 1}

puts(word_count.sort_by {|word,num| -num}.map {|word,num| "#{word}: #{num}"}) # Sorts the hash by the number of times a word is used (the minus makes it descending), then maps each key-value-pair to a string of the form "bla: 3" and then outputs the whole thing.