end
unless base.instance_methods.
include?('parenthesis')
- # Need to raise error
- base.__send__(:include, Parenthesis)
+ # Need to raise error
+ base.__send__(:include, Parenthesis)
end
base.class_eval do
attr_accessor :minus
def to_s_with_minus
return to_s_without_minus unless minus
if @left && @right
- return off_parenthesis { "-#{to_s_without_minus}" }
- end
- if self.parenthesis
- return "(-#{self.value})"
- end
- "-#{self.value}"
+ return off_parenthesis { "-#{to_s_without_minus}" }
+ end
+ if self.parenthesis
+ return "(-#{self.value})"
+ end
+ "-#{self.value}"
end
alias to_s_without_minus to_s
alias to_s to_s_with_minus
def to_latex_with_minus
return to_latex_without_minus unless minus
- return off_parenthesis { "-#{to_latex_without_minus}" }
+ return off_parenthesis { "-#{to_latex_without_minus}" }
end
alias to_latex_without_minus to_latex
alias to_latex to_latex_with_minus
- private
- def off_parenthesis
- self.parenthesis = true unless self.parenthesis
- result = yield
- self.parenthesis = false unless self.parenthesis
- result
- end
+ private
+ def off_parenthesis
+ self.parenthesis = true unless self.parenthesis
+ result = yield
+ self.parenthesis = false unless self.parenthesis
+ result
+ end
end
end
end
def to_s
@value.to_s
end
- alias to_latex to_s
+ alias to_latex to_s
end
class FactorialNode < LiteralNode
def to_s
"#{value}^#{power}"
end
- alias to_latex to_s
+ alias to_latex to_s
end
class RootNode < LiteralNode
Mint::LiteralNode.__send__(:include, Mint::Parenthesis)
def minus(val)
- case val
- when String
+ case val
+ when String
Mint::LiteralNode.new("-#{val}")
- when Mint::LiteralNode
- value = val.value
- val.value = "-#{value}"
- else
- val.minus = true
- val
+ when Mint::LiteralNode
+ value = val.value
+ val.value = "-#{value}"
+ else
+ val.minus = true
+ val
end
end
def node(val)
if val.instance_of?(String)
- return Mint::LiteralNode.new(val)
- end
- val
+ return Mint::LiteralNode.new(val)
+ end
+ val
end
def add_parenthesis(node)
['4 / 4', '4 / 4'],
['5 div 5', '5 div 5'],
['-233/23', '-233 / 23'],
- ['(x^2 + 4)(y^3 - 2)', '(x^2 + 4) * (y^3 - 2)'],
- ['(x^3 + 2)(x^2- 3)', '(x^3 + 2) * (x^2 - 3)'],
+ ['(x^2 + 4)(y^3 - 2)', '(x^2 + 4) * (y^3 - 2)'],
+ ['(x^3 + 2)(x^2- 3)', '(x^3 + 2) * (x^2 - 3)'],
['2(x^2 + xy + y^2)', '2 * (x^2 + x * y + y^2)'],
['sqrt(2(x^(2 + 3) + xyz^5 + y^2))', 'sqrt(2 * (x^(2 + 3) + x * y * z^5 + y^2))'],
['sqrt(2(x^(2 + 3) + root(xyz^5) + y^2))', 'sqrt(2 * (x^(2 + 3) + sqrt(x * y * z^5) + y^2))'],
['5.0 div 4', '5.0 div 4'],
['5/4', '5 / 4'],
['5.0/4', '5.0 / 4'],
- ['.04324134213', '0.04324134213'],
- ['- .04324134213', '-0.04324134213'],
+ ['.04324134213', '0.04'],
+ ['- .04324134213', '-0.04'],
# TODO: need more pattern
]
end