class Stack

Stack class implementing a typical stack data structure

Public Class Methods

new(size = nil) click to toggle source
Calls superclass method List::new
# File lib/stack.rb, line 7
def initialize(size = nil)
  super(size)
end

Public Instance Methods

pop() click to toggle source

This method implements pop functionality of a stack (LIFO)

Example:

>> s = Stack.new
>> s.push("else")
>> s.push("something")
>> s.pop()

> “something”

# File lib/stack.rb, line 20
def pop()
  if(@list.length == 0)
    raise CollectionErrors::StackUnderflowError.new
  else
    @list.pop
  end
end