Sha256: 621100160ffb10644d3aad3b5881c99c6fd91f4d7ddb397aa088ca46f439acef

Contents?: true

Size: 602 Bytes

Versions: 2

Compression:

Stored size: 602 Bytes

Contents

module Bluepill
  module Util
   class RotationalArray < Array
     def initialize(size)
       super
       @index = 0
     end
     
     def push(value)
       self[@index] = value
       @index = (@index + 1) % self.size
       puts @index
     end
     
     alias_method :<<, :push
     
     def pop
       raise "Cannot call pop on a rotational array"
     end

     def shift
       raise "Cannot call shift on a rotational array"
     end

     def unshift
       raise "Cannot call unshift on a rotational array"
     end
     
     def last
       self[@index - 1]
     end
   end
 end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bluepill-0.0.2 lib/bluepill/util/rotational_array.rb
bluepill-0.0.1 lib/bluepill/util/rotational_array.rb