Class: RubyLint::NestedStack

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeNestedStack

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_stackObject

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.

Returns:

  • (TrueClass|FalseClass)


24
25
26
# File 'lib/ruby-lint/nested_stack.rb', line 24

def empty?
  return @values.empty?
end

#popArray

Pops the last stack from the collection and returns it.

Returns:

  • (Array)


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.

Parameters:

  • value (Mixed)


33
34
35
# File 'lib/ruby-lint/nested_stack.rb', line 33

def push(value)
  @values.last << value
end