Skip to content

Instantly share code, notes, and snippets.

@Sixeight
Created September 21, 2008 04:04
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 Sixeight/11837 to your computer and use it in GitHub Desktop.
Save Sixeight/11837 to your computer and use it in GitHub Desktop.
class EmptyStackError < StandardError; end
class Stack
def initialize
@stack = []
@size = 0
end
def empty?
@size == 0
end
def push(val)
@size += 1
@stack << val
end
def pop
raise EmptyStackError if @stack.empty?
@size -= 1
@stack.pop
end
def size
@size
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment