class Hatchet::NestedDiagnosticContext::ContextStack

Public: Class for holding the context stack of a NestedDiagnosticContext.

Deliberately intended to have a similar API to Array to make testing easier.

Attributes

stack[R]

Internal: Gets the internal stack.

Public Class Methods

new(stack = []) click to toggle source

Internal: Creates a new instance.

stack - An Array of values to initialize the stack with (default: []).

# File lib/hatchet/nested_diagnostic_context.rb, line 97
def initialize(stack = [])
  @stack = stack
end

Public Instance Methods

any?() click to toggle source

Public: Returns true if the stack contains any messages, otherwise returns false.

# File lib/hatchet/nested_diagnostic_context.rb, line 104
def any?
  @stack.size != 0
end
clone() click to toggle source

Internal: Returns a clone of the stack.

# File lib/hatchet/nested_diagnostic_context.rb, line 110
def clone
  ContextStack.new(@stack.clone)
end
join(separator = $,) click to toggle source

Public: Returns a String created by converting each message of the stack to a String, separated by separator.

separator - The String to separate the messages of the stack with

(default: $,).

Returns a String created by converting each message of the stack to a String, separated by separator.

# File lib/hatchet/nested_diagnostic_context.rb, line 123
def join(separator = $,)
  @stack.join(separator)
end
pop(n = nil) click to toggle source

Internal: Removes one or more message from the stack.

n - The number of messages to remove from the cstack (default: nil). If

no number is provided then one message will be removed.

Returns the message or messages removed from the context stack. If n was not specified it will return a single message, otherwise it will return an Array of up to n messages.

# File lib/hatchet/nested_diagnostic_context.rb, line 147
def pop(n = nil)
  if n
    @stack.pop(n)
  else
    @stack.pop
  end
end
push(*values) click to toggle source

Internal: Pushes the given messages onto the stack.

values - One or more messages to add to the context stack.

Returns nothing.

# File lib/hatchet/nested_diagnostic_context.rb, line 133
def push(*values)
  @stack.push(*values)
  nil
end
to_a() click to toggle source

Internal: Returns a copy of the stack as an array.

# File lib/hatchet/nested_diagnostic_context.rb, line 157
def to_a
  @stack.clone.to_a
end