Class: GraphLab::Stack
- Inherits:
-
Object
- Object
- GraphLab::Stack
- Defined in:
- lib/graphlab.rb
Overview
Ruby Array-based implementation of a Stack
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 stack.
Instance Method Summary collapse
-
#count ⇒ Object
returns the number of items currently in the stack.
-
#initialize ⇒ Stack
constructor
class constructor.
-
#inspect ⇒ Object
return a string representation of the array.
-
#peek ⇒ Object
peek method.
-
#pop ⇒ Object
pop method.
-
#push(value) ⇒ Object
push method.
-
#to_s ⇒ Object
returns a string representation of the array.
Constructor Details
#initialize ⇒ Stack
class constructor
570 571 572 |
# File 'lib/graphlab.rb', line 570 def initialize @items = Array.new end |
Instance Attribute Details
#drawing ⇒ Object
Struct object to store the attributes of the drawn visualization
567 568 569 |
# File 'lib/graphlab.rb', line 567 def drawing @drawing end |
#items ⇒ Object (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
#count ⇒ Object
returns the number of items currently in the stack
611 612 613 |
# File 'lib/graphlab.rb', line 611 def count return items.count end |
#inspect ⇒ Object
return a string representation of the array
601 602 603 |
# File 'lib/graphlab.rb', line 601 def inspect return to_s end |
#peek ⇒ Object
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 |
#pop ⇒ Object
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_s ⇒ Object
returns a string representation of the array
606 607 608 |
# File 'lib/graphlab.rb', line 606 def to_s return @items.inspect end |