Module: Ratomic::CounterMethods
- Defined in:
- lib/ratomic/counter.rb
Overview
Ruby convenience methods for Counter.
Instance Method Summary collapse
-
#dec(amt = 1) ⇒ void
Decrement the counter.
-
#inc(amt = 1) ⇒ void
Increment the counter.
-
#to_i ⇒ Integer
Coerce the counter to an Integer snapshot.
-
#value ⇒ Integer
Read the current counter value.
-
#zero? ⇒ Boolean
Check whether the current counter value is zero.
Instance Method Details
#dec(amt = 1) ⇒ void
This method returns an undefined value.
Decrement the counter.
43 44 45 46 47 |
# File 'lib/ratomic/counter.rb', line 43 def dec(amt = 1) raise ArgumentError, "amount must be positive: #{amt}" if amt.negative? decrement(amt) end |
#inc(amt = 1) ⇒ void
This method returns an undefined value.
Increment the counter.
32 33 34 35 36 |
# File 'lib/ratomic/counter.rb', line 32 def inc(amt = 1) raise ArgumentError, "amount must be positive: #{amt}" if amt.negative? increment(amt) end |
#to_i ⇒ Integer
Coerce the counter to an Integer snapshot.
16 17 18 |
# File 'lib/ratomic/counter.rb', line 16 def to_i read end |
#value ⇒ Integer
Read the current counter value.
9 10 11 |
# File 'lib/ratomic/counter.rb', line 9 def value read end |
#zero? ⇒ Boolean
Check whether the current counter value is zero.
23 24 25 |
# File 'lib/ratomic/counter.rb', line 23 def zero? read.zero? end |