class Interceptors::DS::Stack

Public Class Methods

new() click to toggle source
# File lib/interceptors/ds/stack.rb, line 8
def initialize
  @head = nil
end

Public Instance Methods

empty?() click to toggle source
# File lib/interceptors/ds/stack.rb, line 25
def empty?
  @head.nil?
end
pop() click to toggle source
# File lib/interceptors/ds/stack.rb, line 19
def pop
  raise NoSuchElementException if empty?

  @head.item.tap { @head = @head.next }
end
push(item) click to toggle source
# File lib/interceptors/ds/stack.rb, line 12
def push(item)
  assert!(item)
  old_head = @head
  @head = Node.new(item)
  @head.next = old_head
end