# frozen_string_literal: true module RubyAlgebra # Команда интерпретатора class Command end # Команда присвоения class AssignmentCommand < Command attr_reader :lhs, :operation, :operand1, :operand2 def initialize(lhs, operation, operand1, operand2) @lhs = lhs @operation = operation @operand1 = operand1 @operand2 = operand2 end def to_s result = @lhs.is_a?(Array) ? @lhs.join(', ') : @lhs.to_s result += ' := ' result += @operand1.to_s case @operation when :add result += ' + ' when :sub result += ' - ' when :mult, :scale result += ' * ' when :div result += ' / ' end result += @operand2.to_s if @operation != :assign result end end # Команда вывода на экран class DisplayCommand < Command attr_reader :polynomial def initialize(polynomial) @polynomial = polynomial end end end