Class: Contender::Counter
- Inherits:
-
Atomic
- Object
- Atomic
- Contender::Counter
- Defined in:
- lib/contender/counter.rb
Overview
Simplified interface to an atomic reference that acts as a counter
Instance Method Summary collapse
-
#decrement ⇒ Integer
Decrements the value of this counter by 1.
-
#increment ⇒ Integer
Increments the value of this counter by 1.
- #initialize(initial = 0) ⇒ undefined constructor
- #inspect ⇒ String
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
#decrement ⇒ Integer
Decrements the value of this counter by 1
19 20 21 22 23 |
# File 'lib/contender/counter.rb', line 19 def decrement update do |count| count = count - 1 end end |
#increment ⇒ Integer
Increments the value of this counter by 1
11 12 13 14 15 |
# File 'lib/contender/counter.rb', line 11 def increment update do |count| count = count + 1 end end |
#inspect ⇒ String
26 27 28 |
# File 'lib/contender/counter.rb', line 26 def inspect "#<Contender::Counter = #{value}>" end |