Skip to content

Instantly share code, notes, and snippets.

@kenmazaika
Created March 7, 2016 20:55
Show Gist options
  • Save kenmazaika/60a673b512dfb18ba147 to your computer and use it in GitHub Desktop.
Save kenmazaika/60a673b512dfb18ba147 to your computer and use it in GitHub Desktop.
a = []
a.push(1) # enqueue the number 1 in the queue
a.push(2) # enqueue the number 2 in the queue
a.push(3) # enqueue the number 3 in the queue
# dequeue the first element, 1 has been in the queue longest
puts a.shift # => displays 1
a.push(4) # enqueue the number 4 in the queue
# dequeue the next element. 1 has been tended to
# already, so tend to the element that has been in
# the queue the longest, in this case 2
puts a.shift # => displays 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment