05/01/29 04:16:34
>>43
作ってみたよー
require 'open-uri'
TARGET_URI = 'URLリンク(www.gnu.org)'
class CharCounter
NON_WORD_CHAR = 'OTHER'
def initialize
@buf = Hash.new{|h, k| h[k] = Hash.new(0)}
@before_char = NON_WORD_CHAR
end # def
def push(s)
s.gsub(/[\r\n]+/, '').split(//).each do |c|
c.downcase!
c = NON_WORD_CHAR if c !~ /[a-zA-Z]/
@buf[@before_char][c] += 1
@before_char = c
end
end # def
def sorted_each
@buf.keys.sort.each do |k|
yield k, @buf[k]
end
end # def
end # class
# 続く