Class: Luoma::ObjectLiteral

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) ⇒ ObjectLiteral

(t_token token, Array items) -> void

Parameters:



940
941
942
943
# File 'lib/luoma/expression.rb', line 940

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

Instance Method Details

#childrenObject



960
961
962
# File 'lib/luoma/expression.rb', line 960

def children
  @items
end

#evaluate(context) ⇒ Object

Signature:

  • (RenderContext) -> untyped



946
947
948
949
950
951
952
953
954
955
956
957
958
# File 'lib/luoma/expression.rb', line 946

def evaluate(context)
  result = {} #: Hash[String, untyped]

  @items.each do |item|
    if item.is_a?(Spread)
      result.update(context.env.to_h(item.expr.evaluate(context), context))
    else
      result[item.key.value] = item.expr.evaluate(context)
    end
  end

  result
end

#to_sObject

Signature:

  • () -> String



965
966
967
# File 'lib/luoma/expression.rb', line 965

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

#with(token) ⇒ self

Parameters:

  • token (Object)

Returns:

  • (self)


969
970
971
972
# File 'lib/luoma/expression.rb', line 969

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