Class: CodeBackbonePointsInstruction
- Inherits:
-
Instruction
- Object
- Instruction
- CodeBackbonePointsInstruction
- Defined in:
- lib/instructions/code/code_backbone_points.rb
Overview
pops the top item from the :code
stack; pushes an :int
with the number of items in the root of the :code
value
note: if the :code
value does not parse, or is an atom (doesn’t parse into a CodeBlockPoint), the result is 0; if it is an empty block, it’s also 0
For example:
[1,2,[3,4],5] -> 4 backbone points
[[1,2,3,4,5]] -> 1 backbone point
[] -> 0 backbone points
1 -> 0 backbone points
needs: 1 :code
pushes: 1 :int
Instance Attribute Summary
Attributes inherited from Instruction
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
38 39 40 |
# File 'lib/instructions/code/code_backbone_points.rb', line 38 def cleanup pushes :int, @result end |
#derive ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/instructions/code/code_backbone_points.rb', line 29 def derive if @parsed.parses? pts = @parsed.linked_code.kind_of?(CodeblockPoint) ? @parsed[1].contents.length : 0 else pts = 0 end @result = ValuePoint.new("int",pts) end |
#preconditions? ⇒ Boolean
20 21 22 |
# File 'lib/instructions/code/code_backbone_points.rb', line 20 def preconditions? needs :code, 1 end |
#setup ⇒ Object
24 25 26 27 |
# File 'lib/instructions/code/code_backbone_points.rb', line 24 def setup arg_blueprint = @context.pop_value(:code) @parsed = NudgeProgram.new(arg_blueprint) end |