"cyclic include" error inside anonymous module

B

Brian Candler

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.
 
T

ts

B> load 'ruby4.rb', true

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

B> module M

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

B> end

B> include M

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

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


Guy Decoux
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top