From: Robert Klemme Date: 2010-01-22T22:53:45+09:00 Subject: [ruby-core:27697] Re: able to re-require $0 2010/1/22 Yusuke ENDOH : > Hi, > > 2010/1/22 Benoit Daloze : >> Hi, >>> In similar, you can require the same library twice. >>> >>> �require "foo" >>> �require "foo" >>> >> Excuse me, but at least in 1.9, >> p require './test' #=> true >> p require './test' #=> false >> (the same happen with a stdlib, like benchmark of course) >> >> It's not loaded the second time. And it's very harmful to load 2 times >> the same file, because it will redefine every method and constant... > > Yes. �I meant to say neither exception nor warning. > OTOH, curcular require yields warning: > > > foo.rb > �require "./bar" > > bar.rb > �require "./foo" > > $ ruby19 -W2 foo.rb > /home/mame/work/ruby/foo.rb:1: warning: loading in progress, circular > require considered harmful - /home/mame/work/ruby/bar.rb > � � � �from foo.rb:1:in `
' > � � � �from foo.rb:1:in `require' > � � � �from /home/mame/work/ruby/bar.rb:1:in `' > � � � �from /home/mame/work/ruby/bar.rb:1:in `require' > � � � �from /home/mame/work/ruby/foo.rb:1:in `' > � � � �from /home/mame/work/ruby/foo.rb:1:in `require' > > > ... Ah, I get Roger's point now. > > > bad.rb: > �require $0 > �p :foo > > $ ruby19 ./bad.rb > :foo > :foo > > > I don't know this is a bug or not, but I guess that Kurt is right. I don't think it's worth fixing because a) it is unlikely that someone requires $0 and b) even if that case would be prevented you can still cause harm by having links in the filesystem pointing to the same file. Fixing that would require quite a bit of file system magic I believe and that is probably not worthwhile because of the time and runtime overhead (might have to do additional FS accesses). My 0.02EUR Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/