Skip to content

Instantly share code, notes, and snippets.

@dbc-challenges
Last active December 13, 2015 22:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dbc-challenges/4988728 to your computer and use it in GitHub Desktop.
Save dbc-challenges/4988728 to your computer and use it in GitHub Desktop.
# A very basic Stack implemented with an array
# Makes use of the built in #pop and # push methods that exist for arrays.
class Stack
def initialize
@store = []
end
def push(x)
@store.push x
end
def pop
raise "Stack Underflow - The stack is empty" if self.empty?
@store.pop
end
def peek
@store.last
end
def empty?
@store.empty?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment