Class: TTFunk::Sum
Overview
Sum aggreaget. Is sums all pushed values.
Instance Attribute Summary collapse
-
#value ⇒ #+
readonly
Value.
Instance Method Summary collapse
-
#<<(operand) ⇒ void
Push a value.
-
#initialize(init_value = 0) ⇒ Sum
constructor
A new instance of Sum.
-
#value_or(_default) ⇒ any
Get the stored value or default.
Constructor Details
#initialize(init_value = 0) ⇒ Sum
Returns a new instance of Sum.
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
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.
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.
Source Code
lib/ttfunk/sum.rb, line 29
29 | def value_or(_default) |
30 | # value should always be non-nil
|
31 | value
|
32 | end
|