(続き)
例えば特定の文字が出てくるたびにインクリメントすればいいと考えれば
最初は↓こういう実装でもいい

s = "Ruby is an object oriented programming language"
result = Hash.new(0)
s.each_char do |char|
result[char.downcase] += 1
end

上のコードが手続き的で副作用が気持ち悪いと思うようになってくればreduceに変える
s.chars.reduce(Hash.new(0)) {|result, char| result[char.downcase] += 1; result}

reduceだとブロックの最後に明示的にresultを返してやらないといけないのが美しくないと思えばeach_with_objectに変える
s.chars.each_with_object(Hash.new(0)) {|char, result| result[char.downcase] += 1}

文字の集合をgroup byすればいいというふうに考えれば↓こういう感じとか(パフォーマンスは上のほうがよいけど)
s.chars.group_by{|char| char.downcase}
.map{|key, value| [key, value.length]}
.to_h

入出力の型を考えて、ロジックを考えて、ロジックをコードで表現する方法を見つける