From: Robert Klemme Date: 2012-12-27T20:02:05+09:00 Subject: Re: Accumulate total count for each month On Wed, Dec 26, 2012 at 10:59 PM, 7stud -- wrote: > Robert Klemme wrote in post #1090246: >> >> >> Why isn't that simple? Did you actually try it? >> >> require 'date' >> >> counts = Hash.new 0 >> >> ARGF.each do |line| >> line.chomp! >> counts[Date.parse(line)] += 1 >> end >> >> counts.sort_by {|d,| k}.each do |d, c| >> printf "%-20s %6d\n", d, c >> end >> >> Cheers >> >> robert >> > > 1.rb:10:in `block in
': undefined local variable or method `k' for > main:Object (NameError) Typo when ad hoc refactoring names require 'date' counts = Hash.new 0 ARGF.each do |line| line.chomp! counts[Date.parse(line)] += 1 end counts.sort_by {|d,| d}.each do |d, c| printf "%-20s %6d\n", d, c end Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/