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
5行目では、2番目の引数は「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