Class: Luoma::DivExpression

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



594
595
596
597
598
599
600
601
# File 'lib/luoma/expression.rb', line 594

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



604
605
606
# File 'lib/luoma/expression.rb', line 604

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