Class: Hist
- Inherits:
-
Object
- Object
- Hist
- Defined in:
- lib/hist.rb
Instance Attribute Summary collapse
-
#max_size ⇒ Object
readonly
Returns the value of attribute max_size.
-
#stack ⇒ Object
readonly
Returns the value of attribute stack.
Instance Method Summary collapse
- #[](i) ⇒ Object
-
#initialize(max_size = 10) ⇒ Hist
constructor
A new instance of Hist.
- #push(obj) ⇒ Object
- #recent(n = nil) ⇒ Object
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_size ⇒ Object (readonly)
Returns the value of attribute max_size.
2 3 4 |
# File 'lib/hist.rb', line 2 def max_size @max_size end |
#stack ⇒ Object (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 |