class Expr def initialize(left, op, right) @left = left @op = op @right = right end end class Expr def to_s s = "(" s += @left.to_s s += @op s += @right.to_s s + ")" end end class Expr def to_f left = @left.to_f right = @right.to_f if @op == "+" then left + right elsif @op == "-" then left - right elsif @op == "*" then left * right elsif @op == "/" then left / right else 0 end end end