From: "Ara.T.Howard" Date: 2003-12-03T04:47:08+09:00 Subject: Re: require bug?? (1.8.0) On Wed, 3 Dec 2003, Andrew Walrond wrote: > Date: Wed, 3 Dec 2003 00:47:43 +0900 > From: Andrew Walrond > Newsgroups: comp.lang.ruby > Subject: require bug?? (1.8.0) > > Require is supposed to include each file only once, but if the same physical > file is accessed from different paths, it can get included multiple times. Is > this the correct behaviour? yes - see other posts. i've used something like this as a workaround before a.rb $lib_a = true ... b.rb $lib_b = true ... c.rb $lib_c = true require 'a' unless defined? $lib_a require 'b' unless defined? $lib_b ... -a > > Example 1 > > File a.rb > puts "a includes b" > require "b.rb" > puts "a includes c" > require "c.rb" > > File b.rb > puts "b includes c" > require "c.rb" > > File c.rb > puts "C INCLUDED" > > $ ruby a.rb > a includes b > b includes c > C INCLUDED > a includes c > > C included once. > > Example 2: > > Change file b.rb > puts "b includes c" > require "./c.rb" > > $ ruby a.rb > a includes b > b includes c > C INCLUDED > a includes c > C INCLUDED > > File c.rb is included twice. > > > -- ATTN: please update your address books with address below! =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328 | STP :: http://www.ngdc.noaa.gov/stp/ | NGDC :: http://www.ngdc.noaa.gov/ | NESDIS :: http://www.nesdis.noaa.gov/ | NOAA :: http://www.noaa.gov/ | US DOC :: http://www.commerce.gov/ | | The difference between art and science is that science is what we | understand well enough to explain to a computer. | Art is everything else. | -- Donald Knuth, "Discover" | | /bin/sh -c 'for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done' ===============================================================================