A
Andrew Walrond
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?
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.
file is accessed from different paths, it can get included multiple times. Is
this the correct behaviour?
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.