Skip to content

Instantly share code, notes, and snippets.

@cristianrasch
Created March 31, 2012 16:49
Show Gist options
  • Save cristianrasch/2266674 to your computer and use it in GitHub Desktop.
Save cristianrasch/2266674 to your computer and use it in GitHub Desktop.
Ruby queue implementation
#!/usr/bin/env ruby
class Queue
def initialize
@arr = []
end
def enqueue(val)
@arr << val
end
def dequeue
@arr.shift
end
def each
@arr.each { |e| yield e }
# while e = dequeue
# yield e
# end
end
end
if __FILE__ == $0
q = Queue.new
(1..10).each { |i| q.enqueue i }
q.each { |e| p "Element is: #{e}" }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment