"cyclic include" error inside anonymous module

> So next question: why, when I define module M inside an anonymous module,
> does Ruby make module M both include and extend the enclosing module?

load("file", true) is a security mechanism but, unlike $SAFE = 4, use it
only with file that you can trust because it's easy to bypass it.

Sorry, that's not what I meant. Let me try asking the question differently:

* Why does Ruby do this strange thing of an implicit 'include <Anon>' and
  'extend <Anon>' in the first place?

Perhaps it would be clearest if you gave an example of why it is needed? I
have given you an example of where it breaks things :slight_smile:

(Aside: this thread was triggered by a question on the mod_ruby mailing
list, where a user asked why strange cyclic include errors happened when he
ran a script under mod_ruby, but it worked fine on its own. I was able to
show him that this was an artefact of load(file,true) - and therefore that
the problem could be reproduced outside of mod_ruby. I'm happy that mod_ruby
needs to run each script inside an anonymous namespace, so that applications
are less likely to tread on each other's top-level namespaces, but I'm now
trying to understand why load(file,true) has to do the things it does which
in turn causes it to break otherwise well-formed scripts)

Thanks,

Brian.

Perhaps it would be clearest if you gave an example of why it is needed? I
have given you an example of where it breaks things :slight_smile:

Use -w with your script

Guy Decoux

* Why does Ruby do this strange thing of an implicit 'include <Anon>' and
  'extend <Anon>' in the first place?

Well, a stupid example

moulon% cat a.rb
def hello
   puts "bonjour"
end

class A
   def hello
      super
   end
end

A.new.hello
moulon%

moulon% ruby a.rb
bonjour
moulon%

moulon% ruby -e 'load("a.rb", true)'
bonjour
moulon%

without the include super will give

in `hello': super: no superclass method `hello' (NoMethodError)

Guy Decoux

Hi,

···

In message "Re: "cyclic include" error inside anonymous module" on Mon, 5 Sep 2005 22:17:06 +0900, Brian Candler <B.Candler@pobox.com> writes:

* Why does Ruby do this strange thing of an implicit 'include <Anon>' and
'extend <Anon>' in the first place?

Just because we want methods and constants defined at the toplevel
available. I admit there's something weird in wrapped load, including
"cyclic include" you've mentioned. I hope it would eventually be
resolved.

              matz.