Sha256: 2cbd345888c52562861c2c137d4725f9800de74ca76e7f070a3f8421fc947e21
Contents?: true
Size: 528 Bytes
Versions: 1
Compression:
Stored size: 528 Bytes
Contents
class Wc attr :filename def initialize(filename) @filename = filename @hash = read Array(hash).sort { |one, two| -(one <=> two) } end def to_text @hash.each { |elem| puts "\"#{elem[0]}\" has #{elem[1]} occurrences" } end private def read() hash = Hash.new { |h, k| h[k] = 0 } File.open(ARGV[0], "r") { |f| f.each_line { |line| words = line.split words.each { |w| hash[w] += 1 } } } hash end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
wc-0.20.0 | lib/wc.rb |