From: Calamitas Date: 2008-07-23T22:12:26+09:00 Subject: Re: circular 'require' On Wed, Jul 23, 2008 at 3:02 PM, Stefano Crocco wrote: > Regarding why your code doesn't work, I think Peter is almost correct in his > analisys, except when he states that the name of the file is stored in $" > before being loaded, in the require case. After actually testing your code > (which I should have done before sending my first mail), I went looking in the > ruby source code to try to understand why the behavior I described wasn't the > observed one. From what I understand (I'm not very good at reading C code), it > seems that ruby has a mechanism which avoids exactly this kind of endless > loop: when it starts requiring a file, it stores it in some kind of table > (which as nothing to do with $"), where it remains until it's been 'fully' > required (that is, until the code it contains, including other requires, has > been executed). While the file is in the table, attempts to require it again > fail, just as it had been put in $". Only at the end of this process, the file > is added to $". For those interested, the involved C functions are > rb_require_safe and load_lock, both in eval.c in the ruby distribution. Good to know it works this way. I wanted to test whether it was actually stored in $", but I was too lazy. Dang! ;-) But either way, something had to break the infinite loop because there was none. Peter