blob: 407173f7b0e8d8ec90f962d607e62bbd93e7127a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
|