Class: Utils::Grepper::Queue
- Inherits:
-
Object
- Object
- Utils::Grepper::Queue
- Defined in:
- lib/utils/grepper.rb
Instance Attribute Summary collapse
-
#max_size ⇒ Object
readonly
Returns the value of attribute max_size.
Instance Method Summary collapse
- #data ⇒ Object
-
#initialize(max_size) ⇒ Queue
constructor
A new instance of Queue.
- #push(x) ⇒ Object (also: #<<)
Constructor Details
#initialize(max_size) ⇒ Queue
Returns a new instance of Queue.
13 14 15 |
# File 'lib/utils/grepper.rb', line 13 def initialize(max_size) @max_size, @data = max_size, [] end |
Instance Attribute Details
#max_size ⇒ Object (readonly)
Returns the value of attribute max_size.
17 18 19 |
# File 'lib/utils/grepper.rb', line 17 def max_size @max_size end |
Instance Method Details
#data ⇒ Object
19 20 21 |
# File 'lib/utils/grepper.rb', line 19 def data @data.dup end |
#push(x) ⇒ Object Also known as: <<
23 24 25 26 27 |
# File 'lib/utils/grepper.rb', line 23 def push(x) @data.shift if @data.size > @max_size @data << x self end |