Class: Luoma::ArrayLiteral

Inherits:
Expression show all
Defined in:
lib/luoma/expression.rb,
sig/luoma/expression.rbs

Instance Attribute Summary

Attributes inherited from Expression

#span, #token

Instance Method Summary collapse

Methods inherited from Expression

#scope

Constructor Details

#initialize(token, items) ⇒ ArrayLiteral

Returns a new instance of ArrayLiteral.

Signature:

  • (t_token token, Array[Expression|Spread] items) -> void

Parameters:



903
904
905
906
# File 'lib/luoma/expression.rb', line 903

def initialize(token, items)
  super(token)
  @items = items
end

Instance Method Details

#childrenObject



923
924
925
# File 'lib/luoma/expression.rb', line 923

def children
  @items
end

#evaluate(context) ⇒ Object

Signature:

  • (RenderContext) -> untyped



909
910
911
912
913
914
915
916
917
918
919
920
921
# File 'lib/luoma/expression.rb', line 909

def evaluate(context)
  result = [] #: Array[untyped]

  @items.each do |item|
    if item.is_a?(Spread)
      result.concat(context.env.to_a(item.expr.evaluate(context), context))
    else
      result << item.evaluate(context)
    end
  end

  result
end

#to_sObject

Signature:

  • () -> String



928
929
930
# File 'lib/luoma/expression.rb', line 928

def to_s
  "[#{@items.join(", ")}]"
end

#with(token) ⇒ self

Parameters:

  • token (t_token)

Returns:

  • (self)


932
933
934
935
# File 'lib/luoma/expression.rb', line 932

def with(token)
  @span = Luoma.span(@token, token)
  self
end