aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/plugins/rspec/examples/passing/stack.rb
diff options
context:
space:
mode:
authorFrancis Irving <francis@mysociety.org>2009-12-02 17:51:30 +0000
committerFrancis Irving <francis@mysociety.org>2009-12-02 17:51:30 +0000
commit5f3139b538d1ff58b719a72d7c7cf05a5b6136b5 (patch)
tree13597cf6751df3122bfb1f1e5b1699e5c7ec5f93 /vendor/plugins/rspec/examples/passing/stack.rb
parentdcf788cab6268a5c9830178d1bdff606f84132ce (diff)
Part of upgrade to rails 2.3.2
Diffstat (limited to 'vendor/plugins/rspec/examples/passing/stack.rb')
-rw-r--r--vendor/plugins/rspec/examples/passing/stack.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/vendor/plugins/rspec/examples/passing/stack.rb b/vendor/plugins/rspec/examples/passing/stack.rb
new file mode 100644
index 000000000..407173f7b
--- /dev/null
+++ b/vendor/plugins/rspec/examples/passing/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