Class: Stack
- Inherits:
-
List
- Object
- Collection
- List
- Stack
- Defined in:
- lib/stack.rb
Overview
Stack class implementing a typical stack data structure
Instance Method Summary collapse
-
#initialize(size = nil) ⇒ Stack
constructor
A new instance of Stack.
-
#pop ⇒ Object
This method implements pop functionality of a stack (LIFO).
Methods inherited from List
Constructor Details
#initialize(size = nil) ⇒ Stack
Returns a new instance of Stack.
7 8 9 |
# File 'lib/stack.rb', line 7 def initialize(size = nil) super(size) end |
Instance Method Details
#pop ⇒ Object
This method implements pop functionality of a stack (LIFO)
Example:
>> s = Stack.new
>> s.push("else")
>> s.push("something")
>> s.pop()
> “something”
20 21 22 23 24 25 26 |
# File 'lib/stack.rb', line 20 def pop() if(@list.length == 0) raise CollectionErrors::StackUnderflowError.new else @list.pop end end |