Class: RubyLint::NestedStack
- Inherits:
-
Object
- Object
- RubyLint::NestedStack
- Defined in:
- lib/ruby-lint/nested_stack.rb
Overview
NestedStack is a basic implementation of a nested stack. It’s primarily used by VirtualMachine for storing variables and values during assignments.
Instance Method Summary collapse
-
#add_stack ⇒ Object
Adds a new stack to push values to.
-
#empty? ⇒ TrueClass|FalseClass
Returns
true
if the stack is empty. -
#initialize ⇒ NestedStack
constructor
A new instance of NestedStack.
-
#pop ⇒ Array
Pops the last stack from the collection and returns it.
-
#push(value) ⇒ Object
Pushes a value to the current (= last) stack.
Constructor Details
#initialize ⇒ NestedStack
Returns a new instance of NestedStack
8 9 10 |
# File 'lib/ruby-lint/nested_stack.rb', line 8 def initialize @values = [] end |
Instance Method Details
#add_stack ⇒ Object
Adds a new stack to push values to.
15 16 17 |
# File 'lib/ruby-lint/nested_stack.rb', line 15 def add_stack @values << [] end |
#empty? ⇒ TrueClass|FalseClass
Returns true
if the stack is empty.
24 25 26 |
# File 'lib/ruby-lint/nested_stack.rb', line 24 def empty? return @values.empty? end |
#pop ⇒ Array
Pops the last stack from the collection and returns it.
42 43 44 |
# File 'lib/ruby-lint/nested_stack.rb', line 42 def pop return @values.pop end |
#push(value) ⇒ Object
Pushes a value to the current (= last) stack.
33 34 35 |
# File 'lib/ruby-lint/nested_stack.rb', line 33 def push(value) @values.last << value end |