Codebase list dnscat2 / d4ef71e5-a4c9-4ef2-8cc1-9cb967576ec6/main server / libs / ring_buffer.rb
d4ef71e5-a4c9-4ef2-8cc1-9cb967576ec6/main

Tree @d4ef71e5-a4c9-4ef2-8cc1-9cb967576ec6/main (Download .tar.gz)

ring_buffer.rb @d4ef71e5-a4c9-4ef2-8cc1-9cb967576ec6/mainraw · history · blame

##
# ring_buffer.rb
# By https://gist.github.com/Nimster/4078106
# Created Sept 18, 2015
#
# See LICENSE.md
##

class RingBuffer < Array
  attr_accessor :max_size

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

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

  alias :push :<<
end