Class: GraphLab::Stack

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

Overview

Ruby Array-based implementation of a Stack

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStack

class constructor



570
571
572
# File 'lib/graphlab.rb', line 570

def initialize
	@items = Array.new
end

Instance Attribute Details

#drawingObject

Struct object to store the attributes of the drawn visualization



567
568
569
# File 'lib/graphlab.rb', line 567

def drawing
  @drawing
end

#itemsObject (readonly)

array used to store the values in the stack



565
566
567
# File 'lib/graphlab.rb', line 565

def items
  @items
end

Instance Method Details

#countObject

returns the number of items currently in the stack



611
612
613
# File 'lib/graphlab.rb', line 611

def count
	return items.count
end

#inspectObject

return a string representation of the array



601
602
603
# File 'lib/graphlab.rb', line 601

def inspect
	return to_s
end

#peekObject

peek method. if a drawing exists, redraw the canvas



584
585
586
587
588
589
# File 'lib/graphlab.rb', line 584

def peek
	if @drawing
		view_stack(self, true)
	end
	return items.first
end

#popObject

pop method. if a drawing exists, redraw the canvas



575
576
577
578
579
580
581
# File 'lib/graphlab.rb', line 575

def pop
	value = items.shift
	if @drawing
		view_stack(self, false)
	end
	return value
end

#push(value) ⇒ Object

push method. if a drawing exists, redraw the canvas



592
593
594
595
596
597
598
# File 'lib/graphlab.rb', line 592

def push(value)
	output = items.unshift(value)
	if @drawing
		view_stack(self, false)
	end
	return output
end

#to_sObject

returns a string representation of the array



606
607
608
# File 'lib/graphlab.rb', line 606

def to_s	
	return @items.inspect
end