Sha256: 4b6f138c8f48627b68a43f881d9138cc0694eb527418bec6ed288694e74fb03c

Contents?: true

Size: 510 Bytes

Versions: 2

Compression:

Stored size: 510 Bytes

Contents

require 'stack_contract'

class Stack

  contract StackContract

  class NoPopForEmptyStack < RuntimeError
  end

  def initialize
    @elements = []
  end

  def initialize_copy(orig)
    @elements = orig.elements
  end

  def elements
    @elements.dup
  end

  def size
    @elements.size
  end

  def empty?
    size == 0
  end

  def top
    @elements.last
  end

  def push(element)
    @elements.push(element)
    nil
  end

  def pop
    raise NoPopForEmptyStack if empty?
    @elements.pop
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
armin-joellenbeck-rdbc-0.0.4 examples/stack.rb
armin-joellenbeck-rdbc-0.0.5 examples/stack.rb