I am trying to sort a document based on the number of times the word appears then alphabetically by the words so when it is outputted it will look something like this.
Try this:
words = {'the' => 6,'we' => 7,'those' => 5,'have' => 3} words.sort { |(x_k, x_v), (y_k, y_v)| [y_v, y_k] <=> [x_v, x_k]} #=> [["we", 7], ["the", 6], ["those", 5], ["have", 3]]