class LimitedArray

Attributes

limit[RW]

Public Class Methods

new(limit) click to toggle source
Calls superclass method
# File lib/utils/limited_array.rb, line 5
def initialize(limit)
  @limit = limit
  super()
end

Public Instance Methods

<<(val) click to toggle source
Calls superclass method
# File lib/utils/limited_array.rb, line 14
def <<(val)
  if full?
    self.rotate!
    self[limit-1] = val
  else
    super
  end
end
average() click to toggle source
# File lib/utils/limited_array.rb, line 23
def average
  sum.to_f / size
end
full?() click to toggle source
# File lib/utils/limited_array.rb, line 10
def full?
  size == limit
end
sum() click to toggle source
# File lib/utils/limited_array.rb, line 27
def sum
  inject(:+)
end