Class: TTFunk::Sum

Inherits:
Aggregate show all
Defined in:
lib/ttfunk/sum.rb

Overview

Sum aggreaget. Is sums all pushed values.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(init_value = 0) ⇒ Sum

Returns a new instance of Sum.

Parameters:

  • init_value (#+) (defaults to: 0)

    initial value

Source Code
lib/ttfunk/sum.rb, line 12
12
def initialize(init_value = 0)
13
  super()
14
  @value = init_value
15
end

Instance Attribute Details

#value#+ (readonly)

Value

Returns:

  • (#+)
Source Code
lib/ttfunk/sum.rb, line 9
9
def value
10
  @value
11
end

Instance Method Details

#<<(operand) ⇒ void

This method returns an undefined value.

Push a value. It will be added to the current value.

Parameters:

  • operand (any)
Source Code
lib/ttfunk/sum.rb, line 21
21
def <<(operand)
22
  @value += coerce(operand)
23
end

#value_or(_default) ⇒ any

Get the stored value or default.

Parameters:

  • _default (any)

    Unused. Here for API compatibility.

Returns:

  • (any)
Source Code
lib/ttfunk/sum.rb, line 29
29
def value_or(_default)
30
  # value should always be non-nil
31
  value
32
end