From: ts Date: 2002-03-14T20:32:47+09:00 Subject: Re: Newbie -- Please help!! >>>>> "F" == "Firestone, Mark <- Technical Support" > writes: F> It works... but I had to use a Global Varible to make it work. That F> MUST be wrong. Why ? there is nothing wrong with global variable when you write a small script. Look, for example, in the distribution of ruby and you'll see that for some scripts global variables are sometimes used. F> class User [...] F> def name F> @name F> end F> def password F> @password F> end It's best to write it attr_reader :name, :password F> def show F> print "User: #@name #@phone #@citystate #@address #@password\n" F> end F> end F> class User_list F> include Enumerable F> def initialize F> @users = Array.new F> end Well here manifestly you want to manage it like an Array, just make User_list inherit from Array and redefine the methods that you want Something like this pigeon% cat b.rb #!/usr/bin/ruby 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 attr_reader :name, :password def show puts "User: #@name #@phone #@citystate #@address #@password\n" end end class User_list < Array def self.loadusers(file = "users.dat") list = nil File.open(file) do |f| list = Marshal.load(f) print "- Loading User Object...\n" end list end def saveusers(file = "users.dat", mode = "w") File.open(file, mode) do |f| Marshal.dump(self, f) end print "- Saving User Object...\n" end def [](key) if key.kind_of?(Integer) result = self[key] else result = find { |user| key == user.name } end end def checkpassword (username,password) result = FALSE if self[username] != nil if self[username].password == password result = TRUE end else print "You passed me a bad user -- ass-munch!\n" end return result end end list = User_list.new list << User.new('SYSOP','000-000-0000','Tempe, AZ', '600 E. Solana Drive','STUPID') list << User.new('TEST','000-000-0000','Mesa, AZ', '123 Sample Street','HAPPY') list.each {|l| l.show } print list.checkpassword('SYSOP','STUPID') print list.checkpassword('SYSOP2','PASSWORD') list.saveusers pigeon% Guy Decoux