Ruby evaluate without eval?

后端 未结 5 469
野性不改
野性不改 2021-01-19 14:32

How could I evaluate at mathematical string without using eval?

Example:

mathstring = \"3+3\"

Anyway that can be evaluated without

5条回答
  •  有刺的猬
    2021-01-19 15:08

    Dentaku seems (I haven't used it yet) like a good solution - it lets you check your (mathematical and logical) expressions, and to evaluate them.

    calculator = Dentaku::Calculator.new
    calculator.evaluate('kiwi + 5', kiwi: 2)
    

提交回复
热议问题