Class: RubyLabs::LinearDSLab::Queue

Inherits:
Object
  • Object
show all
Defined in:
lib/lineardslab.rb

Overview

Ruby Array-based implementation of a queue

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeQueue

class constructor



187
188
189
# File 'lib/lineardslab.rb', line 187

def initialize
	@items = Array.new
end

Instance Attribute Details

#drawingObject

Struct object to store the attributes of the drawn visualization



184
185
186
# File 'lib/lineardslab.rb', line 184

def drawing
  @drawing
end

#itemsObject (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

#countObject

returns the number of items currently in the queue



246
247
248
# File 'lib/lineardslab.rb', line 246

def count
	return items.count
end

#dequeueObject

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

#inspectObject

return a string representation of the array



236
237
238
# File 'lib/lineardslab.rb', line 236

def inspect
	return to_s
end

#peekObject

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

#shiftObject

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_sObject

returns a string representation of the array



241
242
243
# File 'lib/lineardslab.rb', line 241

def to_s	
	return @items.inspect
end