From: 7stud -- Date: 2007-09-24T07:47:09+09:00 Subject: Re: How would you write it vs Smalltalk Simon Kræ—¦ger wrote: > Rick DeNatale schrieb: >> Here's another way: >> >> puts "Enter line:" >> h = Hash.new(0) >> gets.scan(/[a-zA-Z]/) {|ch| h[ch.downcase] += 1 } >> p h.sort > > Well, we need an inject solution, right? > > p gets.downcase.scan(/[a-z]/).inject({}){|h,c| > h.merge({c,h[c].to_i+1})}.sort > How about: p gets.downcase.scan(/[a-z]/).inject(Hash.new(0)){|h, c| h[c]+= 1; h}.sort -- Posted via http://www.ruby-forum.com/.