Class: Dhallish::Ast::TextInterpolationNode

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#partsObject

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