From: Yusuke ENDOH Date: 2011-07-05T02:32:17+09:00 Subject: [ruby-core:37785] Re: [Ruby 1.9 - Bug #4487][Assigned] require_relative fails in an eval'ed file Hello, > �$cat eval_me1.rb > �eval(File.read('eval_me2.rb'), binding, File.expand_path('./eval_me2.rb')) > �$cat eval_me2.rb > �require_relative 'eval_me1.rb' > �$ ruby eval_me1.rb > �C:/dev/ruby/faster_require/spec/eval_me2.rb:1:in `require_relative': cannot infer basepath (LoadError) > � � � �from C:/dev/ruby/faster_require/spec/eval_me2.rb:1:in `
' > � � � �from eval_me1.rb:1:in `eval' > � � � �from eval_me1.rb:1:in `
' > > I suppose was assuming that if eval included a filename, then require_relative would work from within it. Perhaps I am mistaken? I think your expectation is reasonable, though I personally dislike the eval's feature to fake filepath. The following patch makes require_relative use the given file path. I'm afraid if I should include this patch in 1.9.3 because I can't estimate the impact of this patch. What do you think? diff --git a/vm_eval.c b/vm_eval.c index 7df7f5f..3710401 100644 --- a/vm_eval.c +++ b/vm_eval.c @@ -1007,7 +1007,7 @@ eval_string_with_cref(VALUE self, VALUE src, VALUE scope, NODE *cref, const char /* make eval iseq */ th->parse_in_eval++; th->mild_compile_error++; - iseqval = rb_iseq_compile(src, rb_str_new2(file), INT2FIX(line)); + iseqval = rb_iseq_compile_with_option(src, rb_str_new2(file), rb_str_new2(file), INT2FIX(line), Qnil); th->mild_compile_error--; th->parse_in_eval--; -- Yusuke Endoh