From: Brian Candler Date: 2003-05-21T19:44:34+09:00 Subject: Re: Strange mod_ruby On Wed, May 21, 2003 at 04:56:51PM +0900, Dominik Werder wrote: > > It's because you are wrapped in an anonymous module when you use > > mod_ruby, > > so you just created a new Fixnum class in that module, which has nothing > > at > > all to do with 2. > > > > If you put that code into another file and `require' it, it gets added to > > the root namespace. I think you can also do something like > > `2.class.module_eval { ... }', IIRC. > > thank you very much, this one got me really busy the last 2 days :) > > is there a reason for this kind of design? The main reason is that mod_ruby has a single instance of the Ruby interpreter for *all* the scripts which are being run under it. If one script decides to define something in its top-level namespace, you don't want that thing to appear in the top-level namespace of all other scripts - it would couple them together too closely, causing hard-to-find bugs. So each script in run in its own anonymous namespace. But if they 'require' a library, then that goes into the shared top-level namespace: it doesn't make sense for each script to have its own copy of the dbi library, for example. Cheers, Brian.