Class: Luoma::ModExpression
- Inherits:
-
InfixExpression
- Object
- Expression
- InfixExpression
- Luoma::ModExpression
- Defined in:
- lib/luoma/expression.rb,
sig/luoma/expression.rbs
Instance Attribute Summary
Attributes inherited from Expression
Instance Method Summary collapse
Methods inherited from InfixExpression
Methods inherited from Expression
#children, #initialize, #scope
Constructor Details
This class inherits a constructor from Luoma::InfixExpression
Instance Method Details
#evaluate(context) ⇒ Object
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_s ⇒ Object
621 622 623 |
# File 'lib/luoma/expression.rb', line 621 def to_s "#{@left} % #{@right}" end |