class Kaninchen::DataStructure::Stack

Public Class Methods

new(*items) click to toggle source
# File lib/kaninchen/data_structure/stack.rb, line 6
def initialize(*items)
  @stack ||= items
end

Public Instance Methods

<<(item)
Alias for: push
empty?() click to toggle source
# File lib/kaninchen/data_structure/stack.rb, line 26
def empty?
  @stack.size.zero?
end
pop() click to toggle source
# File lib/kaninchen/data_structure/stack.rb, line 16
def pop
 @stack.pop
end
pop!() click to toggle source
# File lib/kaninchen/data_structure/stack.rb, line 20
def pop!
  popped = self.pop
  raise Kaninchen::PopEmptyStackError, 'Popping out empty stack' if popped.nil?
  popped
end
push(item) click to toggle source
# File lib/kaninchen/data_structure/stack.rb, line 10
def push(item)
  @stack.push item
  self
end
Also aliased as: <<
size() click to toggle source
# File lib/kaninchen/data_structure/stack.rb, line 30
def size
  @stack.size
end