aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/plugins/rspec/examples/pure/stack.rb
diff options
context:
space:
mode:
authorfrancis <francis>2008-01-23 01:57:59 +0000
committerfrancis <francis>2008-01-23 01:57:59 +0000
commit6d1733e8a0b5f404326cfbd78b7139c87ecbffa3 (patch)
treec86561445b9ec5179020f8f56afb7b9174b390c5 /vendor/plugins/rspec/examples/pure/stack.rb
parent8bd6667c7885870af45522315f501a2b87340b1a (diff)
Add files new to new rspec
Diffstat (limited to 'vendor/plugins/rspec/examples/pure/stack.rb')
-rw-r--r--vendor/plugins/rspec/examples/pure/stack.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/vendor/plugins/rspec/examples/pure/stack.rb b/vendor/plugins/rspec/examples/pure/stack.rb
new file mode 100644
index 000000000..407173f7b
--- /dev/null
+++ b/vendor/plugins/rspec/examples/pure/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