Class: RubyCollections::Stack
- Inherits:
-
Object
- Object
- RubyCollections::Stack
- Defined in:
- lib/ruby_collections/stack.rb
Instance Method Summary collapse
-
#initialize(arr = []) ⇒ Stack
constructor
A new instance of Stack.
- #isEmpty? ⇒ Boolean
- #pop ⇒ Object
- #push(e) ⇒ Object
- #size ⇒ Object
- #top ⇒ Object
Constructor Details
#initialize(arr = []) ⇒ Stack
Returns a new instance of Stack.
4 5 6 |
# File 'lib/ruby_collections/stack.rb', line 4 def initialize(arr = []) @arr = arr end |
Instance Method Details
#isEmpty? ⇒ Boolean
12 13 14 |
# File 'lib/ruby_collections/stack.rb', line 12 def isEmpty? @arr.size.zero? end |
#pop ⇒ Object
24 25 26 |
# File 'lib/ruby_collections/stack.rb', line 24 def pop @arr.shift end |
#push(e) ⇒ Object
20 21 22 |
# File 'lib/ruby_collections/stack.rb', line 20 def push(e) @arr.unshift(e) end |
#size ⇒ Object
8 9 10 |
# File 'lib/ruby_collections/stack.rb', line 8 def size @arr.size end |
#top ⇒ Object
16 17 18 |
# File 'lib/ruby_collections/stack.rb', line 16 def top @arr[0] end |