From: Vandemoortele Simon Date: 2002-12-26T05:06:54+09:00 Subject: Re: mod_ruby: What is the lifetime of my objects ? Austin Ziegler wrote: > Unless you're instantiating the objects in an object store or > another server-side object environment, the lifetime of a given > object is the lifetime of the webpage/CGI script. > Thus, when you 'require "classes.rb"', unless classes.rb stores the > current state of your objects (and not just the default state), then > you're just getting the default objects. Note that having classes.rb > store the current state is a very BAD idea -- it's not scalable past > one user. > The difference between 'require' and 'load' is that 'load' will > ALWAYS load the file requested, whereas 'require' will load it only > if it hasn't already been loaded (but there's apparently a way to > fool require). > If you want to pass your classes between web pages, you either need > to instantiate a session in an object store/object environment (like > is done with EJB) and reference your objects by session, or pass > them along as hidden parameters (noting that if you do, they may be > subject to improper modification and you probably want to have some > sort of MD5 hash on some or all of the values that also goes out as > part of the hidden parameters). Hmmm, this is indeed the behaviour I would expect. Still I wonder why I get the apache warning message ../classes.rb:15: warning: already initialized constant PictureForm The warning seems to suggest the constant instantiated when form1.rbx loaded 'classes.rb' still existed when form2.rbx loaded 'classes.rb' ... Is that possible ? If so, doesn't that contradict the above ? Simon -- If one cannot enjoy reading a book over and over again, there is no use in reading it at all. -- Oscar Wilde