From: Mike Wilson Date: 2001-02-04T04:19:37+09:00 Subject: [ruby-talk:10316] Re: Local directory search "server" script -----Original Message----- From: "Michael Schuerig" To: "ruby-talk ML" Date: Sat Feb 03 10:10:03 PST 2001 Subject: [ruby-talk:10313] Re: Local directory search "server" script >Mike Wilson wrote: > >> -----Original Message----- >> From: "Michael Schuerig" >> To: "ruby-talk ML" >> Date: Sat Feb 03 06:10:02 PST 2001 >> Subject: [ruby-talk:10306] Re: Local directory search "server" script >> >> >Mike Wilson wrote: >> > >> >> >#! /usr/bin/ruby -w >> >> > >> >> >require 'cgi' >> >> > >> >> > >> >> >def main >> >> > @myname = File.basename($0) >> >> > @searchprog = "agrep -clr" >> >> > @hits = {} >> >> > @totalocc = 0 >> >> > >> >> >> >> ==Possible stupidity disclaimer ;) >> >> I've never seen instance variables used in a non-OO program yet, do you do >> >> that because you create a main method and you want those visible through >> >> the whole file while still being able to define them within your method? I >> >> would've expected $myname, etc, but the @ took me by suprise ;) >> > >> >It's not meant to be clever, it's just the first thing that occurred to >> >me... >> > >> >> I just realized that it's possible that you/someone may have thought that >> the "stupidity disclaimer" was referring to my opinion of what you were >> doing. > >No, I didn't even think of this. And anyway, I'm a Ruby Nuby and >therefore particularly interested in suggestions regarding style. >Actually, I changed the instances vars to globals in the meantime. > >Michael > >-- >Michael Schuerig >mailto:schuerig@acm.org >http://www.schuerig.de/michael/ I wasn't advocating the use of globals (I'm assuming when you say global, you mean $var), only trying to learn what using instance variables brings to the table when not used in class instances. I guess this leads to a question of how to best define variables within ruby. Personally, I usually just define the necessary variables at the top of the file, outside of any method, but I'm not positive that that's the correct way either. Anyone more knowledgable about this that can give advice? Mike Wilson Unix Administrator http://ruby.weblogs.com ___________________________________________________ GO.com Mail Get Your Free, Private E-mail at http://mail.go.com