Sha256: 13b3931cb5f9d07ae119353d2adb950352ad2c31b666a61961bdd30ea87dcac6

Contents?: true

Size: 516 Bytes

Versions: 144

Compression:

Stored size: 516 Bytes

Contents

class StackUnderflowError < RuntimeError
end

class StackOverflowError < RuntimeError
end

class Stack
  
  def initialize
    @items = []
  end
  
  def push object
    raise StackOverflowError if @items.length == 10
    @items.push object
  end
  
  def pop
    raise StackUnderflowError if @items.empty?
    @items.delete @items.last
  end
  
  def peek
    raise StackUnderflowError if @items.empty?
    @items.last
  end
  
  def empty?
    @items.empty?
  end

  def full?
    @items.length == 10
  end
  
end

Version data entries

144 entries across 144 versions & 22 rubygems

Version Path
dchelimsky-rspec-1.1.10 examples/pure/stack.rb
dchelimsky-rspec-1.1.11.1 examples/passing/stack.rb
dchelimsky-rspec-1.1.11.2 examples/passing/stack.rb
dchelimsky-rspec-1.1.11.3 examples/passing/stack.rb
dchelimsky-rspec-1.1.11.4 examples/passing/stack.rb
dchelimsky-rspec-1.1.11.5 examples/passing/stack.rb
dchelimsky-rspec-1.1.11.6 examples/passing/stack.rb
dchelimsky-rspec-1.1.11.7 examples/passing/stack.rb
dchelimsky-rspec-1.1.11 examples/passing/stack.rb
dchelimsky-rspec-1.1.12 examples/passing/stack.rb
dchelimsky-rspec-1.1.99.1 examples/passing/stack.rb
dchelimsky-rspec-1.1.99.13 examples/passing/stack.rb
dchelimsky-rspec-1.1.99.2 examples/passing/stack.rb
dchelimsky-rspec-1.1.99.3 examples/passing/stack.rb
dchelimsky-rspec-1.1.99.4 examples/passing/stack.rb
dchelimsky-rspec-1.1.99.5 examples/passing/stack.rb
dchelimsky-rspec-1.1.99.6 examples/passing/stack.rb
dchelimsky-rspec-1.1.99.7 examples/passing/stack.rb
dchelimsky-rspec-1.1.99.8 examples/passing/stack.rb
dchelimsky-rspec-1.1.99.9 examples/passing/stack.rb