Class: Luoma::ModExpression

Inherits:
InfixExpression 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 InfixExpression

#children, #initialize

Methods inherited from Expression

#children, #initialize, #scope

Constructor Details

This class inherits a constructor from Luoma::InfixExpression

Instance Method Details

#evaluate(context) ⇒ Object

Signature:

  • (RenderContext) -> untyped



611
612
613
614
615
616
617
618
# File 'lib/luoma/expression.rb', line 611

def evaluate(context)
  lhs = context.env.to_numeric(@left.evaluate(context), context, default: :nothing)
  rhs = context.env.to_numeric(@right.evaluate(context), context, default: :nothing)
  return :nothing if lhs == :nothing || rhs == :nothing || rhs.zero? # steep:ignore

  result = lhs.to_d % rhs # steep:ignore
  result.frac.zero? && lhs.is_a?(::Integer) && rhs.is_a?(::Integer) ? result.to_i : result
end

#to_sObject

Signature:

  • () -> String



621
622
623
# File 'lib/luoma/expression.rb', line 621

def to_s
  "#{@left} % #{@right}"
end