Class: ActionStack

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

Overview

Track the actions in a shadow call stack.

Instance Method Summary collapse

Constructor Details

#initializeActionStack

Returns a new instance of ActionStack.



9
10
11
12
# File 'lib/action_stack.rb', line 9

def initialize()
  @bottom = nil
  @top = nil
end

Instance Method Details

#baseObject



18
19
20
# File 'lib/action_stack.rb', line 18

def base()
  @bottom
end

#peekObject



14
15
16
# File 'lib/action_stack.rb', line 14

def peek()
  @top
end

#push(action) ⇒ Action

Place Action at the top of stack.

Parameters:

  • action (Action)

    The action to place.

Returns:

  • (Action)

    The placed action.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/action_stack.rb', line 28

def push(action)

  # Place first action at bottom of stack.
  if @bottom.nil?
    @bottom = action
  # Connect subsequent actions to each other.
  else
    @top.parent = action
    action.child = @top
  end

  # Place action at top of stack.
  @top = action

end