From: dmcnulty@... (Dan McNulty) Date: 2002-02-21T07:19:10+09:00 Subject: Re: Global variables, mod_ruby I am currently also using HTML Template (http://www.0xfa.com/~ikechin/ruby.html) so I can easily separate my HTML from my Ruby. I cannot stand mingling HTML and a language (it seems so ugly to me), so eruby is out. What this means is I have a group of pure Ruby files and a group of pure HTML templates. I am trying hard to keep my code modular, and so I call functions and instantiate objects that are defined in "load"ed files. Of course as you noted, doing this in a web environment introduces some problems because of the way Apache does its thing with mod_ruby. The net effect is that globals don't work in the normal Ruby way and therefore a work-around is needed. I am currently trying to use CGI::Session to store the global variables, which was working, but now its broken again and I can't figure out what I did :-( What I may do is collapse all the globals and return values into a hash and just pass the hash from function-to-function, and always return the same hash back to the caller. This works, but boy is this ugly! Not a very Ruby-ish way of doing things, nor is it good practice in any language. I think I may be encountering life on the frontier, as Ruby does not seem to be used a great deal for web apps. It may be that the tools are just not quite mature enough yet, or it could be I am just not inventive enough :-) What I really want is for mod_ruby to allow Ruby to act like itself. That would be the best thing IMHO. -- Dan Alan Chen wrote in message news:<20020220192350.GB2033@digikata.com>... > On Thu, Feb 21, 2002 at 01:39:01AM +0900, Dan McNulty wrote: > > I see Shugo stated (back in July 2001) that the use of global > > variables when using mod_ruby doesn't work. I am using mod_ruby 0.9.7 > > and it seems support for globals hasn't changed since July. > > > > I very much want to use globals since my alternatives are: > > a) added complexity in the interfaces to certain of my functions > > b) placing all my code into a single file > > > > I don't want to do either of those. Actually, I don't plan to use > > globals in the long term, but it is simple and quick. I will do it > > the right way later. > > > > Does anyone know of any plans to support globals properly using > > mod_ruby, or is there a replacement for mod_ruby that does support > > globals, or is there another alternative to globals besides "a" and > > "b" that I don't know about? > > > > Thanks in advance for any help. > > > > -- Dan > > How exactly do you intend to use the globals? I'm not sure that you > can ever expect to pass data between pages using global variables > when you might have several different apache processes, each with a > different "interpreter-space". > > Re: option b, your code can go into regular ruby files and be required > into eruby pages or ruby scripts. You can split up your code however > it best makes sense to you. I'm not sure how you'd like to use these > globals, but if you have a number of related functions, you can put > then into a common module or class. > > -- alan