Class: Stack

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStack

Returns a new instance of Stack.



3
4
5
# File 'lib/honey_mushroom/stack.rb', line 3

def initialize
  @stack = []
end

Instance Attribute Details

#stackObject

Returns the value of attribute stack.



2
3
4
# File 'lib/honey_mushroom/stack.rb', line 2

def stack
  @stack
end

Instance Method Details

#peekObject



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

def peek
  stack[-1]
end

#popObject



12
13
14
# File 'lib/honey_mushroom/stack.rb', line 12

def pop
  stack.pop
end

#push(value) ⇒ Object



7
8
9
10
# File 'lib/honey_mushroom/stack.rb', line 7

def push(value)
  stack.push(value)
  return value
end