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.
12 13 14 15 |
# File 'lib/ttfunk/sum.rb', line 12 def initialize(init_value = 0) super() @value = init_value end |
Instance Attribute Details
#value ⇒ #+ (readonly)
Value
9 10 11 |
# File 'lib/ttfunk/sum.rb', line 9 def value @value end |
Instance Method Details
#<<(operand) ⇒ void
This method returns an undefined value.
Push a value. It will be added to the current value.
21 22 23 |
# File 'lib/ttfunk/sum.rb', line 21 def <<(operand) @value += coerce(operand) end |
#value_or(_default) ⇒ any
Get the stored value or default.
29 30 31 32 |
# File 'lib/ttfunk/sum.rb', line 29 def value_or(_default) # value should always be non-nil value end |