Class: CodeDefineInstruction
Instance Attribute Summary
Attributes inherited from Instruction
#context
Instance Method Summary
collapse
Methods inherited from Instruction
all_instructions, #go, inherited, #initialize, #needs, #pushes, to_nudgecode
Constructor Details
This class inherits a constructor from Instruction
Instance Method Details
#cleanup ⇒ Object
19
20
|
# File 'lib/instructions/code/code_define.rb', line 19
def cleanup
end
|
#derive ⇒ Object
10
11
12
13
14
15
16
17
18
|
# File 'lib/instructions/code/code_define.rb', line 10
def derive
if @context.variables.keys.include?(@ref)
raise InstructionMethodError, "#{self.class.to_nudgecode} cannot change the value of a variable"
else
new_value = NudgeProgram.new(@code).linked_code
raise InstructionMethodError, "#{self.class.to_nudgecode} cannot parse '#{@code}'" if new_value.is_a?(NilPoint)
@context.names[@ref] = new_value
end
end
|
#preconditions? ⇒ Boolean
2
3
4
5
|
# File 'lib/instructions/code/code_define.rb', line 2
def preconditions?
needs :code, 1
needs :name, 1
end
|
#setup ⇒ Object
6
7
8
9
|
# File 'lib/instructions/code/code_define.rb', line 6
def setup
@ref = @context.pop(:name).name
@code = @context.pop_value(:code)
end
|