Class: CollectionUtils::Stack

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

Instance Method Summary collapse

Constructor Details

#initialize(array = []) ⇒ Stack

Constructors



8
9
10
11
12
13
# File 'lib/collection_utils/stack.rb', line 8

def initialize(array=[])
  @stack = []
  array.each do |element|
    @stack << element
  end
end

Instance Method Details

#is_empty?Boolean



24
25
26
# File 'lib/collection_utils/stack.rb', line 24

def is_empty?
  return @stack.size == 0
end

#peekObject



28
29
30
# File 'lib/collection_utils/stack.rb', line 28

def peek
  return @stack.last
end

#popObject

Public methods



16
17
18
# File 'lib/collection_utils/stack.rb', line 16

def pop()
  return @stack.pop
end

#push(element) ⇒ Object



20
21
22
# File 'lib/collection_utils/stack.rb', line 20

def push(element)
  @stack << element
end

#sizeObject



32
33
34
# File 'lib/collection_utils/stack.rb', line 32

def size
  return @stack.size
end