Class: Liquid2::Negative

Inherits:
Expression show all
Defined in:
lib/liquid2/expressions/arithmetic.rb

Overview

Prefix negation

Instance Attribute Summary

Attributes inherited from Expression

#token

Instance Method Summary collapse

Methods inherited from Expression

#scope

Constructor Details

#initialize(token, right) ⇒ Negative

Returns a new instance of Negative.

Parameters:



85
86
87
88
# File 'lib/liquid2/expressions/arithmetic.rb', line 85

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

Instance Method Details

#childrenObject



100
# File 'lib/liquid2/expressions/arithmetic.rb', line 100

def children = [@right]

#evaluate(context) ⇒ Object



90
91
92
93
94
95
96
97
98
# File 'lib/liquid2/expressions/arithmetic.rb', line 90

def evaluate(context)
  right = context.evaluate(@right)
  value = Liquid2::Filters.to_decimal(right,
                                      default: nil) || context.env.undefined(
                                        "-(#{Liquid2.to_output_string(right)})",
                                        node: self
                                      )
  value.send(:-@)
end