Class: Nudge::CodeblockPoint
- Inherits:
-
ProgramPoint
- Object
- ProgramPoint
- Nudge::CodeblockPoint
- Defined in:
- lib/interpreter/programPoints.rb
Instance Attribute Summary collapse
-
#contents ⇒ Object
Returns the value of attribute contents.
Instance Method Summary collapse
- #blueprint ⇒ Object
- #blueprint_parts ⇒ Object
- #each {|_self| ... } ⇒ Object
- #go(context) ⇒ Object
-
#initialize(contents = []) ⇒ CodeblockPoint
constructor
A new instance of CodeblockPoint.
- #points ⇒ Object
- #tidy(level = 1) ⇒ Object
Constructor Details
#initialize(contents = []) ⇒ CodeblockPoint
Returns a new instance of CodeblockPoint.
43 44 45 46 |
# File 'lib/interpreter/programPoints.rb', line 43 def initialize(contents = []) raise(ArgumentError,"CodeblockPoint must be passed an Array") unless contents.kind_of?(Array) @contents = contents end |
Instance Attribute Details
#contents ⇒ Object
Returns the value of attribute contents.
41 42 43 |
# File 'lib/interpreter/programPoints.rb', line 41 def contents @contents end |
Instance Method Details
#blueprint ⇒ Object
72 73 74 75 |
# File 'lib/interpreter/programPoints.rb', line 72 def blueprint t,b = blueprint_parts return "#{t} \n#{b}".strip end |
#blueprint_parts ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/interpreter/programPoints.rb', line 64 def blueprint_parts fn = self.contents.inject("\n") do |fn_accumulator, branch| rhs = branch.blueprint_parts[1].empty? ? "" : "\n#{branch.blueprint_parts[1]}" fn_accumulator + rhs end return [self.tidy, fn.strip] end |
#each {|_self| ... } ⇒ Object
77 78 79 80 81 82 |
# File 'lib/interpreter/programPoints.rb', line 77 def each yield self @contents.each do |child| child.each {|c| yield c} end end |
#go(context) ⇒ Object
52 53 54 |
# File 'lib/interpreter/programPoints.rb', line 52 def go(context) @contents.reverse.each {|item| context.stacks[:exec].push(item)} end |
#points ⇒ Object
48 49 50 |
# File 'lib/interpreter/programPoints.rb', line 48 def points @contents.inject(1) {|count, daughter| count + daughter.points} end |
#tidy(level = 1) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/interpreter/programPoints.rb', line 56 def tidy(level=1) tt = "block {" indent = level*2 @contents.each {|item| tt += ("\n" + (" "*indent) + item.tidy(level+1))} tt += "}" return tt end |