Skip to content

Instantly share code, notes, and snippets.

@takahashim
Created April 19, 2012 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takahashim/2420317 to your computer and use it in GitHub Desktop.
Save takahashim/2420317 to your computer and use it in GitHub Desktop.
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