class Leafy::Core::Adder

Public Instance Methods

sum_then_reset() click to toggle source

Returns the current sum. The returned value is NOT an atomic snapshot: Invocation in the absence of concurrent updates returns an accurate result, but concurrent updates that occur while the sum is being calculated might not be incorporated.

# File lib/leafy/core/adder.rb, line 12
def sum_then_reset
  x = base
  self.base = 0
  current_cells = cells
  if current_cells
    current_cells.each do |cell|
      if cell
        x += cell.value
        cell.value = 0
      end
    end
  end
  x
end