Class: TTFunk::Min
Overview
Minimum aggregate. Its value can only become lower.
Instance Attribute Summary collapse
-
#value ⇒ Comparable?
readonly
Value.
Instance Method Summary collapse
-
#<<(new_value) ⇒ void
Push a value.
-
#initialize(init_value = nil) ⇒ Min
constructor
A new instance of Min.
-
#value_or(default) ⇒ any
Get the stored value or default.
Constructor Details
#initialize(init_value = nil) ⇒ Min
Returns a new instance of Min.
12 13 14 15 |
# File 'lib/ttfunk/min.rb', line 12 def initialize(init_value = nil) super() @value = init_value end |
Instance Attribute Details
#value ⇒ Comparable? (readonly)
Value
9 10 11 |
# File 'lib/ttfunk/min.rb', line 9 def value @value end |
Instance Method Details
#<<(new_value) ⇒ void
This method returns an undefined value.
Push a value. It will become the new value if it’s lower than the current value (or if there was no value).
22 23 24 25 26 27 28 |
# File 'lib/ttfunk/min.rb', line 22 def <<(new_value) new_value = coerce(new_value) if value.nil? || new_value < value @value = new_value end end |
#value_or(default) ⇒ any
Get the stored value or default.
34 35 36 37 38 |
# File 'lib/ttfunk/min.rb', line 34 def value_or(default) return default if value.nil? value end |