Class: Liquid2::ArrayLiteral
- Inherits:
-
Expression
- Object
- Expression
- Liquid2::ArrayLiteral
- Defined in:
- lib/liquid2/expressions/array.rb
Overview
An array literal.
Instance Attribute Summary
Attributes inherited from Expression
Instance Method Summary collapse
- #children ⇒ Object
- #evaluate(context) ⇒ untyped
-
#initialize(token, items) ⇒ ArrayLiteral
constructor
A new instance of ArrayLiteral.
Methods inherited from Expression
Constructor Details
#initialize(token, items) ⇒ ArrayLiteral
Returns a new instance of ArrayLiteral.
10 11 12 13 |
# File 'lib/liquid2/expressions/array.rb', line 10 def initialize(token, items) super(token) @items = items end |
Instance Method Details
#children ⇒ Object
43 |
# File 'lib/liquid2/expressions/array.rb', line 43 def children = @items |
#evaluate(context) ⇒ untyped
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/liquid2/expressions/array.rb', line 17 def evaluate(context) result = [] # : Array[untyped] @items.each do |item| value = context.evaluate(item) if item.is_a?(ArraySpread) case value when Array result.concat(value) when Hash, String result << value when Enumerable result.concat(value.to_a) else if value.respond_to?(:each) result.concat(value.each) else result << value end end else result << value end end result end |