Class: Fixjour::Counter

Inherits:
Object show all
Defined in:
lib/fixjour/counter.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCounter

Returns a new instance of Counter.



22
23
24
# File 'lib/fixjour/counter.rb', line 22

def initialize
  @value = 0
end

Class Method Details

.counter(key) ⇒ Object



8
9
10
11
# File 'lib/fixjour/counter.rb', line 8

def counter(key)
  counters[key] ||= new
  counters[key].next
end

.reset(key = nil) ⇒ Object



4
5
6
# File 'lib/fixjour/counter.rb', line 4

def reset(key=nil)
  key ? counters.delete(key) : counters.clear
end

Instance Method Details

#nextObject



26
27
28
# File 'lib/fixjour/counter.rb', line 26

def next
  @value += 1
end