Created
April 19, 2012 11:14
-
-
Save takahashim/2420317 to your computer and use it in GitHub Desktop.
This file contains 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 SymbolStack | |
class Error < StandardError | |
end | |
def initialize(max_size = 10) | |
@stack = [] | |
@max_size = max_size | |
end | |
def size | |
@stack.size | |
end | |
def pop | |
if @stack.size <= 0 | |
raise SymbolStack::Error, "stack is empty" | |
else | |
@stack.pop | |
end | |
end | |
def push(elem) | |
if !elem.kind_of? Symbol | |
raise SymbolStack::Error, "argument should be symbol" | |
elsif @stack.size >= @max_size | |
raise SymbolStack::Error, "stack is full" | |
else | |
@stack.push(elem) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment