Module: Equation::Multitive2

Defined in:
lib/equation_grammar.rb

Instance Method Summary collapse

Instance Method Details

#value(ctx:) ⇒ Object



712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
# File 'lib/equation_grammar.rb', line 712

def value(ctx:)
  base = head.value(ctx: ctx)
  tail.elements.each do |k|
    case k.operator.text_value
      when '*'
        base *= k.operand.value(ctx: ctx)
      when '/'
        base /= k.operand.value(ctx: ctx)
      when '%'
        base %= k.operand.value(ctx: ctx)
    end
  end

  base
end