Sha256: 83c2bfa50d105bb435bc88032603a6f1d166245e801321164eb7a93ac6cdcee0

Contents?: true

Size: 317 Bytes

Versions: 2

Compression:

Stored size: 317 Bytes

Contents

class Hist
  attr_reader :stack, :max_size

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

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

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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
array_scanner-0.0.2 lib/hist.rb
array_scanner-0.0.1 lib/hist.rb