examples/stack.rb in armin-joellenbeck-rdbc-0.0.6 vs examples/stack.rb in armin-joellenbeck-rdbc-0.0.7
- old
+ new
@@ -21,57 +21,21 @@
def size
@objects.size
end
- # doctest: A new Stack should be empty.
- # >> stack = Stack.new
- # >> stack.empty?
- # => true
def empty?
size == 0
end
- # doctest: A new Stack should have no object on top.
- # >> stack = Stack.new
- # >> begin
- # ?> stack.top
- # ?> rescue Test::Unit::AssertionFailedError
- # ?> true
- # ?> else
- # ?> false
- # ?> end
- # => true
def top
@objects.last
end
- # doctest: From a new Stack no object can be popped.
- # >> stack = Stack.new
- # >> begin
- # ?> stack.pop
- # ?> rescue Test::Unit::AssertionFailedError
- # ?> true
- # ?> else
- # ?> false
- # ?> end
- # => true
def pop
@objects.pop
end
- # doctest: A pushed object should be on the top.
- # >> stack = Stack.new
- # >> object = Object.new
- # >> stack.push(object)
- # >> stack.empty?
- # => false
- # >> stack.top
- # => object
- # >> stack.pop
- # => object
- # >> stack.empty?
- # => true
def push(object)
@objects.push(object)
nil
end