added RSpec and RSpec on Rails
This commit is contained in:
parent
ddd5b4cf19
commit
3f607d565b
316 changed files with 23828 additions and 0 deletions
36
vendor/gems/rspec-1.1.2/examples/pure/stack.rb
vendored
Normal file
36
vendor/gems/rspec-1.1.2/examples/pure/stack.rb
vendored
Normal file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue