aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/plugins/rspec/examples/stack.rb
diff options
context:
space:
mode:
authorlouise <louise>2007-10-16 19:10:21 +0000
committerlouise <louise>2007-10-16 19:10:21 +0000
commitd350850897a5ee7a994d3c618529cf5beecf71ea (patch)
tree39de7013d0a3377f063fbd53da7c89f207eeedd0 /vendor/plugins/rspec/examples/stack.rb
parent3b1d8bfdeea68da1ad083a305d0df8f458c362a0 (diff)
Adding rspec plugin
Diffstat (limited to 'vendor/plugins/rspec/examples/stack.rb')
-rw-r--r--vendor/plugins/rspec/examples/stack.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/vendor/plugins/rspec/examples/stack.rb b/vendor/plugins/rspec/examples/stack.rb
new file mode 100644
index 000000000..407173f7b
--- /dev/null
+++ b/vendor/plugins/rspec/examples/stack.rb
@@ -0,0 +1,36 @@
+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