From: Calamitas Date: 2008-07-23T21:43:02+09:00 Subject: Re: circular 'require' On Wed, Jul 23, 2008 at 1:39 PM, Shadowfirebird wrote: > I think that Stefano is assuming that Ruby has some sort of defense > from infinite loops. Which is not unreasonable, but I've no idea if > he is right. Other than that, his explanation fits perfectly with my > perception of events. > > Interesting. Yes, something got lost in the cut and paste: One > should inherit from Two. I guess I just fiddled with the example and > didn't retest it; dumb of me. > > Very odd how it works if you remove that, since test1.rb is referring > to Two anyway. > > test1.rb should read: > > require "test2.rb" > class One < Two > def self.testone(); Two.whoistwo; end > def self.whoisone(); puts "class one"; end > end I see. I quoted "executable code" because declarations in Ruby too are executable code. Everything is. Even require is. The execution order I posted in my other post shows you the problem: everything after the require in test1.rb is executed before everything after the require in test2.rb, so you inherit from Two before Two is defined. To me, the reference to Two in the class definition is executable code. Really, it is, you can put any expression there: inherit_from_two = true class One < (inherit_from_two ? Two : Three) end Peter