Class: CodeReplaceNthPointInstruction
Overview
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
27
28
29
|
# File 'lib/instructions/code/code_replace_nth_point.rb', line 27
def cleanup
pushes :code, @result
end
|
#derive ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/instructions/code/code_replace_nth_point.rb', line 11
def derive
acceptor = NudgeProgram.new(@accept)
raise InstructionMethodError,
"#{self.class.to_nudgecode} cannot work with unparseable code" unless acceptor.parses?
insertion = NudgeProgram.new(@insert)
raise InstructionMethodError,
"#{self.class.to_nudgecode} cannot work with unparseable code" unless insertion.parses?
scale = acceptor.points
which_pt = if @where < 1 || @where > scale
(@where % acceptor.points) + 1
else
@where
end
new_tree = acceptor.replace_point(which_pt, insertion.linked_code).blueprint
@result = ValuePoint.new("code", new_tree)
end
|
#preconditions? ⇒ Boolean
2
3
4
5
|
# File 'lib/instructions/code/code_replace_nth_point.rb', line 2
def preconditions?
needs :int, 1
needs :code, 2
end
|
#setup ⇒ Object
6
7
8
9
10
|
# File 'lib/instructions/code/code_replace_nth_point.rb', line 6
def setup
@where = @context.pop_value(:int)
@accept = @context.pop_value(:code)
@insert = @context.pop_value(:code)
end
|