Created
April 19, 2012 13:05
-
-
Save takai/2420855 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StackEmptyError < StandardError | |
end | |
class StackOverflowError < StandardError | |
end | |
class SymbolStack | |
def initialize | |
@stack = [] | |
end | |
def push(obj) | |
raise ArgumentError unless obj.instance_of? Symbol | |
raise StackOverflowError if @stack.size >= 10 | |
@stack.push(obj) | |
end | |
def pop | |
raise StackEmptyError if @stack.empty? | |
@stack.pop | |
end | |
def size | |
@stack.size | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment