From: "Firestone, Mark - Technical Support" Date: 2002-03-14T19:49:00+09:00 Subject: Newbie -- Please help!! First an apology for asking what are probably lamer questions. Second, some backround... I am attempting to learn object orientated programming. I used to write programs in things you guys will probably not like, such as Turbo Pascal. (In fact, I learned to program when I was 10 on a PDP 11/70 running Oregon Pascal II) ...and... I co-wrote a BBS program in my youth. As part of the retrobbs "thing" I want to bring it back as a telnet system with multi-user chat, and stuff... ...which brings me to my problem. I was going to do this in freepascal, but a character named Wayne Conrad (who is an old time friend of mine and helped much with the old software) talked me into doing it in Ruby. Great. I like Ruby. The idea seems really cool. I just DON'T UNDERSTAND IT! I've read the book. I can't wait for the movie. Anyway... I wrote a little bit of code to read and write a user object to disk, verify passwords and such. It works... but I had to use a Global Varible to make it work. That MUST be wrong. I want the whole user thing to be encapsulated so that it gets queried by the rest of the program.. but the rest of the program doesn't know / care what the object is doing. Every time I try to make it do this, the sky falls on me. Here is my sample code, how can I fix it to do what I want?? I've been messing about with this for quite a while... with no luck. Thanks!! Mark Firestone http://www.retrobbs.org class User def initialize(name,phone,citystate,address,password) @deleted = FALSE @locked = TRUE @name = name @alais = '' @alaisOn = FALSE @phone = phone @citystate = citystate @address = address @password = password @width = 80 end def name @name end def password @password end def show print "User: #@name #@phone #@citystate #@address #@password\n" end end class User_list include Enumerable def initialize @users = Array.new end def append(aUser) @users.push(aUser) self end def [](key) if key.kind_of?(Integer) result = @users[key] else result = @users.find { |user| key == user.name } end return result end end #of Class User_list def loadusers File.open("users.dat") do |f| $list = Marshal.load(f) print "- Loading User Object...\n" end end def saveusers File.open("users.dat", "w+") do |f| Marshal.dump($list, f) end print "- Saving User Object...\n" end def checkpassword (username,password) result = FALSE if $list[username] != nil if $list[username].password == password result = TRUE end else print "You passed me a bad user -- ass-munch!\n" end return result end $list = User_list.new #$list.append(User.new('SYSOP','000-000-0000','Tempe, AZ','600 E. Solana Drive','STUPID')) #$list.append(User.new('TEST','000-000-0000','Mesa, AZ','123 Sample Street','HAPPY')) loadusers $list[0].show $list[1].show if $list['TEST'] != nil $list['TEST'].show end print checkpassword('SYSOP','STUPID') print checkpassword('SYSOP2','PASSWORD') saveusers NOTICE: This e-mail and any attachment(s) may contain confidential and proprietary information of Goss International Corporation and/or its subsidiaries and may be legally privileged. This e-mail is intended solely for the addressee. If you are not the addressee, dissemination, copying or other use of this e-mail or any of its content is strictly prohibited and may be unlawful. If you are not the intended recipient please inform the sender immediately and destroy the e-mail and any copies. All liability for viruses is excluded to the fullest extent permitted by law. Any views expressed in this message are those of the individual sender. No contract may be construed by this e-mail.