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
Internal: Gets the internal stack.
Public Class Methods
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
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
Internal: Returns a clone of the stack.
# File lib/hatchet/nested_diagnostic_context.rb, line 110 def clone ContextStack.new(@stack.clone) end
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
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
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
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