I recently released Dentaku, a gem for parsing and evaluating math and logic expressions in Ruby. You can use it to evaluate expressions like:
calculator = Dentaku::Calculator.new calculator.evaluate('10 + 2') => 12
This is not especially useful, but you can also use named variables that get substituted in at runtime, like so:
calculator.evaluate('10 * x', :x => 3) => 30
So what would something like this be useful for? Check out "Dentaku - a calculator for Ruby", my blog article that explains the motivation behind the gem with a use case.
January 26, 2012