From: Shugo Maeda Date: 2004-04-02T12:01:54+09:00 Subject: [ruby-dev:23305] top_include() with ruby_wrapper 前田です。 top_include()の挙動が1.6から変わったせいで、以下のようなコードが 1.8ではエラーになるようです。 --- b.rb --- module A module B end end ----------- --- test.rb --- p A::B include A p B -------------- excelsior:/tmp$ ruby1.6 -v -r b -e 'load("./test.rb", true)' ruby 1.6.8 (2003-07-09) [i386-linux] A::B A::B excelsior:/tmp$ ruby1.8 -v -r b -e 'load("./test.rb", true)' ruby 1.8.1 (2004-02-03) [i386-linux] A::B ./test.rb:2: warning: main#include in the wrapped load is effective only for toplevel ./test.rb:3: uninitialized constant #::B (NameError) from -e:1:in `load' from -e:1 なぜか、以下のようにloadされるライブラリ側からrequireすると動くよ うです。 --- test2.rb require "b" p A::B include A p B ------------ excelsior:/tmp$ ruby1.8 -v -e 'load("./test2.rb", true)' ruby 1.8.1 (2004-02-03) [i386-linux] A::B A::B top_include()の実装を見ると、selfにモジュールをextendしているよう ですが、こんな感じでruby_wrapperにincludeするのでは何かまずいんでしたっけ? diff -u -r1.652 eval.c --- eval.c 2 Apr 2004 02:36:47 -0000 1.652 +++ eval.c 2 Apr 2004 03:01:15 -0000 @@ -7222,8 +7222,7 @@ { rb_secure(4); if (ruby_wrapper) { - rb_warn("main#include in the wrapped load is effective only for toplevel"); - return rb_obj_extend(argc, argv, self); + return rb_mod_include(argc, argv, ruby_wrapper); } else { return rb_mod_include(argc, argv, rb_cObject); -- 前田 修吾