This seems to be a problem of mod_ruby.
Ruby itself and irb handle this right.
···
----- Original Message -----
From: “Dominik Werder” dwerder@gmx.net
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 like2.class.module_eval { … }’, IIRC.
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
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.
···
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
So, how does one create an anonymous module (ie, one without a name
or a name that can be guaranteed to be unique)?
···
On Wednesday, 21 May 2003 at 19:44:34 +0900, Brian Candler wrote:
On Wed, May 21, 2003 at 04:56:51PM +0900, Dominik Werder wrote:
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.
–
Jim Freeze
No animal should ever jump on the dining room furniture unless
absolutely certain he can hold his own in conversation.
– Fran Lebowitz
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
Does that mean that all apache processes use a single ruby interpreter or
do they have an interpreter on theire own?
As far as I understand, each worker process is independent and has its own
Ruby instance.
what should I do if I want to change the behavior of Fixnum in one project
but doesn’t want to disturb the other project?
I don’t know if that’s possible with mod_ruby. If you need that you could
use fastcgi instead (apache mod_fastcgi + ruby fcgi) where each application has its own process or pool of processes.
Regards,
Brian.
···
On Wed, May 21, 2003 at 08:20:27PM +0900, Dominik Werder wrote:
Or, to create an anonymous module and run some code inside it, use
Kernel#load(filename,true)
Cheers,
Brian.
···
On Thu, May 22, 2003 at 12:51:04PM +0900, Jim Freeze wrote:
On Wednesday, 21 May 2003 at 19:44:34 +0900, Brian Candler wrote:
On Wed, May 21, 2003 at 04:56:51PM +0900, Dominik Werder wrote:
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.
So, how does one create an anonymous module (ie, one without a name
or a name that can be guaranteed to be unique)?
what should I do if I want to change the behavior of Fixnum in one
project but doesn’t want to disturb the other project?
I don’t know if that’s possible with mod_ruby. If you need that you could
use fastcgi instead (apache mod_fastcgi + ruby fcgi) where each application has its own process or pool of processes.
what should I do if I want to change the behavior of Fixnum in one
project but doesn’t want to disturb the other project?
Why don’t you make a singleton for the object instead of the class?
because I want all new numbers to have this new function…