Class: Accumulators::MinMax
- Inherits:
-
Object
- Object
- Accumulators::MinMax
- Defined in:
- lib/accumulators/minmax.rb
Instance Attribute Summary collapse
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
Instance Method Summary collapse
Instance Attribute Details
#max ⇒ Object (readonly)
Returns the value of attribute max.
4 5 6 |
# File 'lib/accumulators/minmax.rb', line 4 def max @max end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
3 4 5 |
# File 'lib/accumulators/minmax.rb', line 3 def min @min end |
Instance Method Details
#add(rhs) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/accumulators/minmax.rb', line 6 def add(rhs) if rhs.is_a? Numeric @min = [@min, rhs].min rescue rhs @max = [@max, rhs].max rescue rhs elsif rhs.is_a? self.class @min = [@min, rhs.min].min rescue rhs.min @max = [@max, rhs.max].max rescue rhs.max else raise ArgumentError.new("You may not add #{rhs.class} to #{self.class}") end end |