implement interpreter and demo + bug fixes

- implement interpreter and demo
- replace StandardError with appropriate subclasses
- implement division
- rewrite Polynomial.simplify()
This commit is contained in:
2026-04-13 19:33:50 +03:00
parent f283d039c1
commit 1fff529e83
6 changed files with 221 additions and 99 deletions

View File

@@ -3,6 +3,11 @@
module RubyAlgebra
# Команда интерпретатора
class Command
attr_reader :type
def type
raise NotImplementedError
end
end
# Команда присвоения
@@ -39,20 +44,29 @@ module RubyAlgebra
end
result
end
def type
:assignment
end
end
# Команда вывода на экран
class DisplayCommand < Command
attr_reader :polynomial
attr_reader :item
def initialize(polynomial)
@polynomial = polynomial
def initialize(item)
@type = :display
@item = item
end
def to_s
result = "Display command: "
result += @polynomial.to_s
result += @item.to_s
result
end
def type
:display
end
end
end