From: Austin Ziegler Date: 2002-12-26T04:07:12+09:00 Subject: Re: mod_ruby: What is the lifetime of my objects ? On Thu, 26 Dec 2002 02:46:32 +0900, Vandemoortele Simon wrote: > Assuming I put 'require "classes.rb"' at the beginning of > form1.rbx When I click *Submit* in form1.rbx and get to form2.rbx, > what happens to the objects instantiated in 'classes.rb' in the > following 3 cases: > - form2.rbx contains a 'require classes.rb' statement > - form2.rbx contains a 'load classes.rb' statement > - form2.rbx contains neither > Do they disappear ? Can I still access them ? 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). -austin -- Austin Ziegler, austin@halostatue.ca on 2002.12.25 at 13.57.29