Class: LEAP::Motion::Utils::History

Inherits:
Array
  • Object
show all
Defined in:
lib/leap/motion/utils/history.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(max_size, enum = nil) ⇒ History

Returns a new instance of History.



7
8
9
10
# File 'lib/leap/motion/utils/history.rb', line 7

def initialize(max_size, enum = nil)
  @max_size = max_size
  enum.each { |e| self << e } if enum
end

Instance Attribute Details

#max_sizeObject (readonly)

Returns the value of attribute max_size.



5
6
7
# File 'lib/leap/motion/utils/history.rb', line 5

def max_size
  @max_size
end

Instance Method Details

#<<(el) ⇒ Object Also known as: push



12
13
14
15
16
17
18
19
# File 'lib/leap/motion/utils/history.rb', line 12

def <<(el)
  if self.size < @max_size || @max_size.nil?
    super
  else
    self.shift
    self.push(el)
  end
end