Class: RubyLabs::LinearDSLab::Queue
- Inherits:
-
Object
- Object
- RubyLabs::LinearDSLab::Queue
- Defined in:
- lib/lineardslab.rb
Overview
Ruby Array-based implementation of a queue
Instance Attribute Summary collapse
-
#drawing ⇒ Object
Struct object to store the attributes of the drawn visualization.
-
#items ⇒ Object
readonly
array used to store the values in the queue.
Instance Method Summary collapse
-
#<<(value) ⇒ Object
enqueue method.
-
#count ⇒ Object
returns the number of items currently in the queue.
-
#dequeue ⇒ Object
dequeue method.
-
#enqueue(value) ⇒ Object
enqueue method.
-
#initialize ⇒ Queue
constructor
class constructor.
-
#inspect ⇒ Object
return a string representation of the array.
-
#peek ⇒ Object
peek method.
-
#shift ⇒ Object
dequeue method.
-
#to_s ⇒ Object
returns a string representation of the array.
Constructor Details
#initialize ⇒ Queue
class constructor
187 188 189 |
# File 'lib/lineardslab.rb', line 187 def initialize @items = Array.new end |
Instance Attribute Details
#drawing ⇒ Object
Struct object to store the attributes of the drawn visualization
184 185 186 |
# File 'lib/lineardslab.rb', line 184 def drawing @drawing end |
#items ⇒ Object (readonly)
array used to store the values in the queue
182 183 184 |
# File 'lib/lineardslab.rb', line 182 def items @items end |
Instance Method Details
#<<(value) ⇒ Object
enqueue method. an alternative.
218 219 220 221 222 223 224 |
# File 'lib/lineardslab.rb', line 218 def <<(value) output = items << value if @drawing view_queue(self, false) end return output end |
#count ⇒ Object
returns the number of items currently in the queue
246 247 248 |
# File 'lib/lineardslab.rb', line 246 def count return items.count end |
#dequeue ⇒ Object
dequeue method. if a drawing exists, redraw the canvas
192 193 194 195 196 197 198 |
# File 'lib/lineardslab.rb', line 192 def dequeue value = items.shift if @drawing view_queue(self, false) end return value end |
#enqueue(value) ⇒ Object
enqueue method. if a drawing exists, redraw the canvas
209 210 211 212 213 214 215 |
# File 'lib/lineardslab.rb', line 209 def enqueue(value) output = items << value if @drawing view_queue(self, false) end return output end |
#inspect ⇒ Object
return a string representation of the array
236 237 238 |
# File 'lib/lineardslab.rb', line 236 def inspect return to_s end |
#peek ⇒ Object
peek method. if a drawing exists, redraw the canvas
201 202 203 204 205 206 |
# File 'lib/lineardslab.rb', line 201 def peek if @drawing view_queue(self, true) end return items.first end |
#shift ⇒ Object
dequeue method. an alternative.
227 228 229 230 231 232 233 |
# File 'lib/lineardslab.rb', line 227 def shift value = items.shift if @drawing view_queue(self, false) end return value end |
#to_s ⇒ Object
returns a string representation of the array
241 242 243 |
# File 'lib/lineardslab.rb', line 241 def to_s return @items.inspect end |