Class: Accumulators::MinMax

Inherits:
Object
  • Object
show all
Defined in:
lib/accumulators/minmax.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#maxObject (readonly)

Returns the value of attribute max.



4
5
6
# File 'lib/accumulators/minmax.rb', line 4

def max
  @max
end

#minObject (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