All pastes #940495 Raw Edit

Stuff

public text v1 · immutable
·published 2008-03-13 00:33 UTC
rendered paste body
class Learner
	def learn(text)
		words = text.split(/[^a-zA-Z]/)
		freqs = Hash.new(0)
		words.each { |word| freqs[word] += 1 }
	end
end

puts "Teach me something\n\n"
Learner.new
text = gets.chomp
learn text

#words = text.split(/[^a-zA-Z]/)
#freqs = Hash.new(0)
#words.each { |word| freqs[word] += 1 }
@freqs = freqs.sort_by {|x,y| y }
@freqs.reverse!
@freqs.each {|word, freq| puts word+' '+freq.to_s}