From: "John Mr." Date: 2010-02-25T03:54:23+09:00 Subject: Create a counter in a hash to return first 10 results only New to ruby.. I created a hash array and everything works fine except I can't figure out how to include a counter to return the first 10 results only. Thanks John Here is the code h = Hash.new good_words.each { |w| if h.has_key?(w) h[w] = h[w] + 1 else h[w] = 1 end } # sort the hash by value, and then print it in this sorted order h.sort{|a,b| b[1]<=>a[1]}.each { |elem| puts "\"#{elem[0]}\" has #{elem[1]} occurrences" } -- Posted via http://www.ruby-forum.com/.