Class: Gobstones::Runner::ExecutionContext

Inherits:
Object
  • Object
show all
Defined in:
lib/gobstones/runner/execution_context.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeExecutionContext

Returns a new instance of ExecutionContext.



12
13
14
# File 'lib/gobstones/runner/execution_context.rb', line 12

def initialize
  @values = {}
end

Class Method Details

.for_program(program) ⇒ Object



8
9
10
# File 'lib/gobstones/runner/execution_context.rb', line 8

def self.for_program(program)
  ProgramExecutionContext.new(program)
end

Instance Method Details

#clear(variable_name) ⇒ Object



24
25
26
# File 'lib/gobstones/runner/execution_context.rb', line 24

def clear(variable_name)
  @values.delete(variable_name)
end

#get(variable_name) ⇒ Object



20
21
22
# File 'lib/gobstones/runner/execution_context.rb', line 20

def get(variable_name)
  @values[variable_name] || undefined_variable_error(variable_name)
end

#has_variable_named?(name) ⇒ Boolean

Returns:



28
29
30
# File 'lib/gobstones/runner/execution_context.rb', line 28

def has_variable_named?(name)
  @values.keys.any? { |variable| variable.named?(name) }
end

#program_contextObject



32
33
34
# File 'lib/gobstones/runner/execution_context.rb', line 32

def program_context
  subclass_responsibility
end

#set(variable_name, value) ⇒ Object



16
17
18
# File 'lib/gobstones/runner/execution_context.rb', line 16

def set(variable_name, value)
  @values[variable_name] = value
end