[英]private method 'eval' called for Math:Module (NoMethodError)
I can not figure out how to use this method. 我不知道如何使用此方法。 It seems really strange to me that it should be a private method within Math, as that would make it completely non-accessible for developers (as far as I can tell). 在我看来,这应该是Math中的私有方法真的很奇怪,因为这会使开发人员完全无法访问它(据我所知)。 What am I missing? 我想念什么?
My code is below: 我的代码如下:
str = "(5+9)/(3+4)"
puts Math.eval(str)
I am not sure, what you are trying to achieve, but while str
has a valid ruby syntax (the one from the example above has), here you go: 我不确定您要实现的目标,但是当str
具有有效的ruby语法(上面示例中的语法)时,您可以执行以下操作:
▶ str = "(5+9)/(3+4)"
#⇒ "(5+9)/(3+4)"
▶ instance_eval str
#⇒ 2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.