Skip to content

Instantly share code, notes, and snippets.

@ploubser
Created March 5, 2013 16:06
Show Gist options
  • Select an option

  • Save ploubser/5091382 to your computer and use it in GitHub Desktop.

Select an option

Save ploubser/5091382 to your computer and use it in GitHub Desktop.
class RoundedQueue
attr_accessor :index
def initialize(base = [])
@queue = base
@index = 0
end
def get
if @index >= @queue.size - 1
rv = @queue[@index]
@index = 0
return rv
else
rv = @queue[@index]
@index += 1
return rv
end
end
def push(x)
@queue.push(x)
end
def append(x)
if (@index + 1) > @queue.size
@queue.push(x)
else
@queue.insert((@index + 1), x)
end
end
end
a = RoundedQueue.new([1,2,3,4,5])
while(true)
puts a.get
sleep(0.2)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment