Class: Myco::DEV::Counter

Inherits:
Object
  • Object
show all
Defined in:
lib/myco/dev/counter.rb

Class Method Summary collapse

Class Method Details

.collObject



6
7
8
9
10
11
# File 'lib/myco/dev/counter.rb', line 6

def coll
  @coll ||= begin
    at_exit { print! }
    Hash.new(0)
  end
end

.count(*items) ⇒ Object



13
14
15
# File 'lib/myco/dev/counter.rb', line 13

def count(*items)
  coll[items] += 1
end

.print!Object



17
18
19
20
21
22
# File 'lib/myco/dev/counter.rb', line 17

def print!
  STDOUT.puts "#{self} report:"
  coll.to_a.sort_by { |x| x.last }.each do |key,val|
    STDOUT.puts "  #{val} : #{key.inspect}"
  end
end