]> git.openstreetmap.org Git - rails.git/blob - vendor/gems/rspec-1.1.2/examples/pure/stack.rb
407173f7b0e8d8ec90f962d607e62bbd93e7127a
[rails.git] / vendor / gems / rspec-1.1.2 / examples / pure / stack.rb
1 class StackUnderflowError < RuntimeError
2 end
3
4 class StackOverflowError < RuntimeError
5 end
6
7 class Stack
8   
9   def initialize
10     @items = []
11   end
12   
13   def push object
14     raise StackOverflowError if @items.length == 10
15     @items.push object
16   end
17   
18   def pop
19     raise StackUnderflowError if @items.empty?
20     @items.delete @items.last
21   end
22   
23   def peek
24     raise StackUnderflowError if @items.empty?
25     @items.last
26   end
27   
28   def empty?
29     @items.empty?
30   end
31
32   def full?
33     @items.length == 10
34   end
35   
36 end