Class: Hist

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(max_size = 10) ⇒ Hist

Returns a new instance of Hist.



4
5
6
7
# File 'lib/hist.rb', line 4

def initialize(max_size = 10)
  @stack = []
  @max_size = max_size
end

Instance Attribute Details

#max_sizeObject (readonly)

Returns the value of attribute max_size.



2
3
4
# File 'lib/hist.rb', line 2

def max_size
  @max_size
end

#stackObject (readonly)

Returns the value of attribute stack.



2
3
4
# File 'lib/hist.rb', line 2

def stack
  @stack
end

Instance Method Details

#[](i) ⇒ Object



18
19
20
# File 'lib/hist.rb', line 18

def [](i)
  @stack[i]
end

#push(obj) ⇒ Object



9
10
11
12
# File 'lib/hist.rb', line 9

def push(obj)
  @stack.pop if @stack.size == @max_size
  @stack.unshift(obj)
end

#recent(n = nil) ⇒ Object



14
15
16
# File 'lib/hist.rb', line 14

def recent(n = nil)
  n ? @stack.take(n) : @stack.first
end