changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/examples/pure/stack.rb

changeset 15: 64acf98d15f4
author: moriq@moriq.com
date: Mon Mar 10 10:12:58 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec
1class StackUnderflowError < RuntimeError
2end
3
4class StackOverflowError < RuntimeError
5end
6
7class 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
36end