From: "naruse (Yui NARUSE)" Date: 2012-07-06T18:59:29+09:00 Subject: [ruby-core:46230] [ruby-trunk - Bug #4487] require_relative fails in an eval'ed file Issue #4487 has been updated by naruse (Yui NARUSE). Eregon (Benoit Daloze) wrote: > shyouhei (Shyouhei Urabe) wrote: > > Current require_relative loads relative from where the require_relative command is written. So when in IRB sessions, it fails to infer where it is beacuse the command is written in a non-file (console). > > > > OTOH load loads from process PWD, which is possible in IRB. > > > > So the point is, if you want require_relative to work on an IRB session, you have to define "from where require_relative should search relativeness". > > From the process current working directory I guess, especially since you almost always launch IRB from a terminal. > > Personally I'm doing `require './myfile'` which is not the most elegant, but if you don't have completion in IRB, that's shorter to type. > > Otherwise, there's always the option to do `irb -I.` and use plain `require`. require_relative is introduced to avoid accidentally require a malicious file on the current working directory. So it can't be acceptable. Use require or load on such case. ---------------------------------------- Bug #4487: require_relative fails in an eval'ed file https://bugs.ruby-lang.org/issues/4487#change-27858 Author: rogerdpack (Roger Pack) Status: Assigned Priority: Normal Assignee: matz (Yukihiro Matsumoto) Category: Target version: ruby -v: - =begin Hello all. $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? Thanks! -r =end -- http://bugs.ruby-lang.org/