作者:mingtong77_491_981 | 来源:互联网 | 2023-05-17 18:06
Whilemigratingcodefromruby1.8.6to2.0Inoticedthatthebehaviourofevalwithbindingshasc
While migrating code from ruby 1.8.6 to 2.0 I noticed that the behaviour of eval with bindings has changed. I did not find any information about that and the documentation of those methods has not changed its wording.
在将代码从ruby 1.8.6迁移到2.0时,我注意到带有绑定的eval的行为已经改变。我没有找到任何有关这方面的信息,这些方法的文档没有改变其措辞。
object = Math
binding = object.__send__(:binding)
puts eval("self", binding)
puts eval("sin(0.2)", binding)
gives in irb1.8:
在irb1.8中给出:
> Math
> 0.1986…
and in irb2.0:
并在irb2.0中:
> main
> NoMethodError
I get the same when using the new binding.eval("self")
使用新的binding.eval(“self”)时我也一样
What is the underlying change, and how can I implement the previous behavior in Ruby 2.0?
什么是潜在的变化,我如何在Ruby 2.0中实现以前的行为?
1 个解决方案