lib/calculator.rb in optimus-ep-0.5 vs lib/calculator.rb in optimus-ep-0.5.5

- old
+ new

@@ -29,18 +29,20 @@ infixl(char('/') >> Div, 40). infixl(char('%') >> Mod, 40). prefix(char('-') >> Neg, 60) expr = nil float_parser = number.map(&To_f) + string_parser = regexp(/[_a-z]\S*/i) grouping_parser = char('(') >>(lazy{expr})<< char(')') - term = alt(float_parser, grouping_parser) + term = alt(float_parser, grouping_parser, string_parser) delim = whitespace.many_ expr = delim >> Expressions.build(term, ops, delim) @parser = expr << eof end def compute(expression) ans = @parser.parse(expression) + return ans if ans.is_a?(String) if (ans - ans.to_i) == 0 ans = ans.to_i end return ans.to_s end \ No newline at end of file