Skip to content

Instantly share code, notes, and snippets.

@takahashilabo
Created December 24, 2012 02:26
Show Gist options
  • Save takahashilabo/4367170 to your computer and use it in GitHub Desktop.
Save takahashilabo/4367170 to your computer and use it in GitHub Desktop.
長さ制限つきのQueue
#長さ制限つきのQueue
class Q
attr_accessor :q
def initialize(size)
@q = []
@size = size
end
def push(data)
@q.push data
@q.shift if @q.size > @size
self
end
end
q = Q.new(3)
q.push(1).push(2).push(3).push(4)
p q.q
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment