Class: Dhallish::Ast::TextInterpolationNode
- Inherits:
-
Object
- Object
- Dhallish::Ast::TextInterpolationNode
- Defined in:
- lib/ast.rb
Overview
‘parts` should be a list of ruby-strings and other ast-nodes that shall be interpolated.
Instance Attribute Summary collapse
-
#parts ⇒ Object
Returns the value of attribute parts.
Instance Method Summary collapse
- #compute_type(ctx) ⇒ Object
- #evaluate(ctx) ⇒ Object
-
#initialize(parts) ⇒ TextInterpolationNode
constructor
A new instance of TextInterpolationNode.
Constructor Details
#initialize(parts) ⇒ TextInterpolationNode
Returns a new instance of TextInterpolationNode.
126 127 128 |
# File 'lib/ast.rb', line 126 def initialize(parts) @parts = parts end |
Instance Attribute Details
#parts ⇒ Object
Returns the value of attribute parts.
125 126 127 |
# File 'lib/ast.rb', line 125 def parts @parts end |
Instance Method Details
#compute_type(ctx) ⇒ Object
130 131 132 133 134 135 |
# File 'lib/ast.rb', line 130 def compute_type(ctx) parts.each_with_index { |part, idx| assert ("TextInterpolationNode: expression at index #{idx} not a Text") { part.is_a? String or part.compute_type(ctx) == Types::Text } } Types::Text end |
#evaluate(ctx) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/ast.rb', line 137 def evaluate(ctx) tmp = @parts.reduce("") { |str, part| if part.is_a? String str + part else val = part.evaluate ctx str + val end } tmp end |