Sha256: d60b0562e8d434d9dd98159d359e1c0b2d8fbdff88f7290f4ac9feac19f48d92

Contents?: true

Size: 532 Bytes

Versions: 2

Compression:

Stored size: 532 Bytes

Contents

# encoding: utf-8
# frozen_string_literal: true

module Carbon
  # A mutable counter for giving out incremental ids.
  #
  # @api private
  class Counter
    # The value.
    # @return [::Numeric]
    attr_reader :value

    # Initialize the counter.
    #
    # @param value [::Numeric] The initial value of the counter.
    def initialize(value = 0)
      @value = value
    end

    # Increments the counter by one, and returns the new value.
    #
    # @return [::Numeric]
    def increment
      @value += 1
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
carbon-core-0.2.1 lib/carbon/counter.rb
carbon-core-0.2.0 lib/carbon/counter.rb