Class: Contender::Counter

Inherits:
Atomic
  • Object
show all
Defined in:
lib/contender/counter.rb

Overview

Simplified interface to an atomic reference that acts as a counter

Instance Method Summary collapse

Constructor Details

#initialize(initial = 0) ⇒ undefined



5
6
7
# File 'lib/contender/counter.rb', line 5

def initialize(initial = 0)
  super initial
end

Instance Method Details

#decrementInteger

Decrements the value of this counter by 1

Returns:

  • (Integer)

    The new value of this counter



19
20
21
22
23
# File 'lib/contender/counter.rb', line 19

def decrement
  update do |count|
    count = count - 1
  end
end

#incrementInteger

Increments the value of this counter by 1

Returns:

  • (Integer)

    The new value of this counter



11
12
13
14
15
# File 'lib/contender/counter.rb', line 11

def increment
  update do |count|
    count = count + 1
  end
end

#inspectString

Returns:

  • (String)


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

def inspect
  "#<Contender::Counter = #{value}>"
end