Class: Mementus::IntegerId
- Inherits:
-
Object
- Object
- Mementus::IntegerId
- Defined in:
- lib/mementus/integer_id.rb
Instance Method Summary collapse
-
#initialize(start_value = 1) ⇒ IntegerId
constructor
A new instance of IntegerId.
- #next_id ⇒ Object
Constructor Details
#initialize(start_value = 1) ⇒ IntegerId
Returns a new instance of IntegerId.
5 6 7 8 |
# File 'lib/mementus/integer_id.rb', line 5 def initialize(start_value=1) @current_value = start_value @mutex = Mutex.new end |
Instance Method Details
#next_id ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/mementus/integer_id.rb', line 10 def next_id @mutex.lock allocated = @current_value @current_value += 1 @mutex.unlock allocated end |