From: "Stephan Kämper" Date: 2003-03-08T03:17:04+09:00 Subject: Re: Array of Objects? Frank Thomas wrote: > Hi@all! > > Is it possible to make an array of objects with ruby? I thought of making a > kind of address-manager. It uses a class "Contact", which contains the main > data. now i want to make a class "Abook" which can make many instances of > the class "Contact". If there is not the possibility of using arrays, what > other options exist?? Sure: class Contact # whatever you code... def initialize( aname = "Noname", astreet = "default" , atown = "not set" ) @name, @street, @town = aname, astreet, atown end def to_s "Name: #@name, Street: #@street, Town: #@town" end end ary = [] # Or 'Array.new' if you prefer that... ary << Contact.new("Your Name") ary[2] = Contact.new( "MyName", "Some street") # Note that ary[1] will be nil now... puts ary You may put about anything in your arrays or whatever. Hope this helped, Stephan