From: Christian Boos Date: 2002-02-22T22:18:07+09:00 Subject: RE: recursive require Hello, > -----Original Message----- > From: ysantoso@thomases.com [mailto:ysantoso@thomases.com]On Behalf Of > Yohanes Santoso > Sent: Friday, February 22, 2002 12:00 PM > To: ruby-talk ML; undisclosed-recipients: > Subject: Re: recursive require ... > Here are three files, abc.rb, xyz.rb, and global.rb. abc contains > class Abc, and xyz contains class Xyz. Abc and Xyz are > inter-dependant. Putting "require 'xyz'" in abc.rb and "require > 'abc'" in xyz.rb will not work as you pointed out. > > So, pre-declare class Abc in xyz.rb and pre-declare class Xyz in > abc.rb. However, rather than putting the declaration everywhere, > collect them into a file: global.rb. > > Then, from abc.rb and xyz.rb require global.rb > ... While forward decl. could work that way in Ruby, I think it is a pattern coming from C/C++ that doesn't need to be transposed in Ruby. In this case, I would suggest requiring the other file just before you need it: === abc.rb === class Abc def Abc.name "abc" end def whoami puts "abc knows xyz:" require 'xyz' puts Xyz.name puts "abc tells the truth" end end a = Abc.new a.whoami === xyz.rb === class Xyz def Xyz.name "xyz" end def whoami puts "xyz knows abc:" require 'abc' puts Abc.name puts "xyz tells the truth" end end x = Xyz.new x.whoami === *ruby* === irb(main):001:0> require 'abc' abc knows xyz: xyz knows abc: abc xyz tells the truth xyz abc tells the truth true -- Christian