Ryan Mckenzie wrote in post #1011936:
> Hi Robert,
>
> Your example works perfectly, thank you!

You're welcome!

> To incorporate the occurence count for each keyword do we need to put it
> into a hash similar to the first example I gave or is it possible to
> directly link that up with the output?

Please see what I called "counting idiom" above.

> # sort the hash by value, and then print it in this sorted order
> h.sort{|a,b| a[1]<=>b[1]}.each { |elem|
>   puts "\"#{elem[0]}\" has #{elem[1]} occurrences"
> }

To print in descending order you can as well do

counts.sort_by {|w,c| -c}.each do |w,c|
  printf "%6d %s\n", c, w
end

Kind regards

robert

-- 
Posted via http://www.ruby-forum.com/.