class Que
Attributes
id[R]
max_size[R]
type[R]
Public Class Methods
new(data={})
click to toggle source
# File lib/que.rb, line 11 def initialize(data={}) @type = "Que" @id = @@QueueID @list = Queue.new @@QueueID += 1 @max_size = $DEFAULT_QUE_SIZE @max_size = data[:size] if data[:size] push_list(data[:list]) if data[:list] end
Public Instance Methods
clear()
click to toggle source
# File lib/que.rb, line 41 def clear @list.clear end
display()
click to toggle source
# File lib/que.rb, line 65 def display @list.to_s end
empty?()
click to toggle source
# File lib/que.rb, line 53 def empty? length==0 end
length()
click to toggle source
# File lib/que.rb, line 45 def length @list.length end
pop()
click to toggle source
# File lib/que.rb, line 21 def pop if @list.size<1 puts "Empty collection! Can't pop()" elsif @list.pop end end
push(x)
click to toggle source
# File lib/que.rb, line 29 def push(x) begin if @list.size>=max_size puts "Full collection! Can't push(#{x.to_s})" elsif @list.push(x) end rescue puts "Unable to push #{x.to_s}" end end
push_list(list)
click to toggle source
# File lib/que.rb, line 57 def push_list(list) begin list.each { |data| @list.push data } if list.is_a? Array rescue puts "Unable to push list #{list.to_s}" end end
size()
click to toggle source
# File lib/que.rb, line 49 def size length end