Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
为什么Binding#eval调用块,但Kernel#eval不调用?
Binding#eval
Kernel#eval
def bar; binding; end bi = bar {|x| p(x+1)} bi.eval "yield 2" # ==> 3 eval "yield 2", binding # ==> LocalJumpError
我认为,在第五行,第二个参数必须是“bi”:
$ ruby -v ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-linux] 1 def bar; binding; end 2 bi = bar {|x| p(x+1)} 3 4 bi.eval "yield 2" #==> 3 5 eval "yield 2", bi #==> 3