right end end class Product def initialize(left, right) @left = left @right = right end end class Constant def initialize(value) @value = value end end
right end end class Product def initialize(left, right) @left = left @right = right end end class Constant def initialize(value) @value = value end end class Variable def initialize(name) @name = name end end
right end def evaluate(input) left_node = @left.evaluate(input) right_node = @right.evaluate(input) Node.new( '+', left_node.value + right_node.value, [left_node, right_node], ) end end
right end def evaluate(input) left_node = @left.evaluate(input) right_node = @right.evaluate(input) Node.new( '*', left_node.value * right_node.value, [left_node, right_node], ) end end