Created
December 24, 2012 02:26
-
-
Save takahashilabo/4367170 to your computer and use it in GitHub Desktop.
長さ制限つきのQueue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #長さ制限つきの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