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
jnstq-acts_as_sms-0.1.0 test/vendor/plugins/rspec/examples/pure/stack.rb
jnstq-acts_as_sms-0.1.1 test/vendor/plugins/rspec/examples/pure/stack.rb
jnstq-acts_as_sms-0.1.3 test/vendor/plugins/rspec/examples/pure/stack.rb
jnstq-acts_as_sms-0.1.4 test/vendor/plugins/rspec/examples/pure/stack.rb
newbamboo-evented-rspec-1.1.12 examples/passing/stack.rb
newbamboo-rspec-1.1.12 examples/passing/stack.rb
rspec-instructure-1.3.3 examples/passing/stack.rb
radiant-1.0.0 ruby-debug/ruby/1.8/gems/rspec-1.3.2/examples/passing/stack.rb
rspec-1.3.2 examples/passing/stack.rb
rspec-1.3.1 examples/passing/stack.rb
rspec-1.3.1.rc examples/passing/stack.rb
merb-core-1.1.3 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/examples/pure/stack.rb
merb-core-1.1.2 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/examples/pure/stack.rb
merb-core-1.1.1 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/examples/pure/stack.rb
rspec-core-2.0.0.beta.9 example_specs/passing/stack.rb
rspec-core-2.0.0.beta.8 example_specs/passing/stack.rb
rspec-core-2.0.0.beta.7 example_specs/passing/stack.rb
rspec-core-2.0.0.beta.6 example_specs/passing/stack.rb
rspec-core-2.0.0.beta.5 example_specs/passing/stack.rb
merb-core-1.1.0 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/examples/pure/stack.rb