Class: Luoma::StringLiteral
- Inherits:
-
Expression
- Object
- Expression
- Luoma::StringLiteral
- Defined in:
- lib/luoma/expression.rb,
sig/luoma/expression.rbs
Instance Attribute Summary collapse
-
#segments ⇒ Array[String|Expression]
readonly
Returns the value of attribute segments.
Attributes inherited from Expression
Instance Method Summary collapse
- #children ⇒ Object
- #evaluate(context) ⇒ Object
-
#initialize(token, segments, end_token) ⇒ StringLiteral
constructor
(t_token, Array, t_token).
- #to_s ⇒ Object
-
#value ⇒ String?
() -> String?.
- #with(token) ⇒ self
Methods inherited from Expression
Constructor Details
#initialize(token, segments, end_token) ⇒ StringLiteral
(t_token, Array, t_token)
753 754 755 756 757 |
# File 'lib/luoma/expression.rb', line 753 def initialize(token, segments, end_token) super(token) @segments = segments @span = Luoma.span(token, end_token) end |
Instance Attribute Details
#segments ⇒ Array[String|Expression] (readonly)
Returns the value of attribute segments.
750 751 752 |
# File 'lib/luoma/expression.rb', line 750 def segments @segments end |
Instance Method Details
#children ⇒ Object
766 767 768 |
# File 'lib/luoma/expression.rb', line 766 def children @segments.grep_v(String) #: Array[Expression] end |
#evaluate(context) ⇒ Object
760 761 762 763 764 |
# File 'lib/luoma/expression.rb', line 760 def evaluate(context) @segments.map do |s| s.is_a?(String) ? s : context.env.to_string(s.evaluate(context), context) end.join end |
#to_s ⇒ Object
771 772 773 |
# File 'lib/luoma/expression.rb', line 771 def to_s @segments.map { |s| s.is_a?(String) ? s : "${#{s}}" }.join.inspect end |
#value ⇒ String?
() -> String?
782 783 784 |
# File 'lib/luoma/expression.rb', line 782 def value @segments.first if @segments.length == 1 && @segments.first.is_a?(String) #: String? end |