Class: Carbon::Counter Private

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A mutable counter for giving out incremental ids.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value = 0) ⇒ Counter

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize the counter.

Parameters:

  • value (::Numeric) (defaults to: 0)

    The initial value of the counter.



16
17
18
# File 'lib/carbon/counter.rb', line 16

def initialize(value = 0)
  @value = value
end

Instance Attribute Details

#value::Numeric (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The value.

Returns:

  • (::Numeric)


11
12
13
# File 'lib/carbon/counter.rb', line 11

def value
  @value
end

Instance Method Details

#increment::Numeric

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Increments the counter by one, and returns the new value.

Returns:

  • (::Numeric)


23
24
25
# File 'lib/carbon/counter.rb', line 23

def increment
  @value += 1
end