"cyclic include" error inside anonymous module

(Brian Candler) #1

I'm looking for an explanation of the following:

$ ruby -v
ruby 1.8.2 (2004-12-25) [i386-freebsd5]

$ cat ruby3.rb
load 'ruby4.rb', true

$ cat ruby4.rb
module M
end
include M

$ ruby ruby3.rb
./ruby4.rb:3:in `append_features': cyclic include detected (ArgumentError)
        from ./ruby4.rb:3:in `include'
        from ./ruby4.rb:3
        from ruby3.rb:1:in `load'
        from ruby3.rb:1

My understanding of load(filename,true) was that the code would be wrapped
inside an anonymous module, which I thought of as being like

    module FOOBARrandom123456
    ... code goes here
    end

But that doesn't explain the 'cyclic include' which running ruby3.rb gives
(but not running ruby4.rb by itself)

Thanks,

Brian.

(ts) #2

load 'ruby4.rb', true

ruby create an anonymous module (wrapper) to make the load and protect
(i.e. clone) main (ruby_top_self)

module M

each time a module is created, ruby include/extend the wrapper in it.

end

include M

when you make the include, it detect the wrapper (it's in module).
Consequence :

./ruby4.rb:3:in `append_features': cyclic include detected (ArgumentError)

Guy Decoux