lib/piglet/field/infix_expression.rb in piglet-0.2.0 vs lib/piglet/field/infix_expression.rb in piglet-0.2.2
- old
+ new
@@ -16,10 +16,21 @@
def simple?
false
end
def to_s
- "#{parenthesise(@left_expression)} #{@operator} #{parenthesise(@right_expression)}"
+ left = @left_expression
+ right = @right_expression
+
+ if left.respond_to?(:operator) && left.operator != @operator
+ left = parenthesise(left)
+ end
+
+ if right.respond_to?(:operator) && right.operator != @operator
+ right = parenthesise(right)
+ end
+
+ "#{left} #{@operator} #{right}"
end
private
def determine_type(left, right)
\ No newline at end of file