Class: CollectionUtils::Stack
- Inherits:
-
Object
- Object
- CollectionUtils::Stack
- Defined in:
- lib/collection_utils/stack.rb
Instance Method Summary collapse
-
#initialize(array = []) ⇒ Stack
constructor
Constructors.
- #is_empty? ⇒ Boolean
- #peek ⇒ Object
-
#pop ⇒ Object
Public methods.
- #push(element) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(array = []) ⇒ Stack
Constructors
8 9 10 11 12 13 |
# File 'lib/collection_utils/stack.rb', line 8 def initialize(array=[]) @stack = [] array.each do |element| @stack << element end end |
Instance Method Details
#is_empty? ⇒ Boolean
24 25 26 |
# File 'lib/collection_utils/stack.rb', line 24 def is_empty? return @stack.size == 0 end |
#peek ⇒ Object
28 29 30 |
# File 'lib/collection_utils/stack.rb', line 28 def peek return @stack.last end |
#pop ⇒ Object
Public methods
16 17 18 |
# File 'lib/collection_utils/stack.rb', line 16 def pop() return @stack.pop end |
#push(element) ⇒ Object
20 21 22 |
# File 'lib/collection_utils/stack.rb', line 20 def push(element) @stack << element end |
#size ⇒ Object
32 33 34 |
# File 'lib/collection_utils/stack.rb', line 32 def size return @stack.size end |