From: Stefan Codrescu Date: 2009-03-23T05:41:02+09:00 Subject: Re: Newbie needs help with first project --000325579e82a6355a0465bb35cc Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Yes there is a way to do that... class Game def initialize(title,platform,genre,rating,published_by,developed_by,year,condition) @title=title @platform=platform @genre=genre @rating=rating @published_by=published_by @developed_by=developed_by @year=year @condition=condition @my_file = File.new("/Users/Stefan/Ruby/yourfileorthenameofthefileyouwanttocreate.txt", 'a+') end def to_s puts "Games: #{@title}--#{@platform}--#{@genre}--#{@rating}--#{@published_by}--#{@developed_by}--#{@year}--#{@condition}" end def savedata @my_file.puts "Games: #{@title}--#{@platform}--#{@genre}--#{@rating}--#{@published_by}--#{@developed_by}--#{@year}--#{@condition}" end def printdata file = File.open("/Users/Stefan/Ruby/yourfileorthenameofthefileyouwanttocreate.txt") file.each {|info| print info} end end game1=Game.new(" FireProReturns","Playstation_2","Sports","Teen", "Good","Agetec_Inc.","2000","Very_Good") game1.to_s game1.savedata game1.printdata the a+ means that it will create a new file and write to it or it will add on to the end of that file if it already exists. and I also added a method that will print the file that you made. also note that since the file is in the a+ mode if you run the program 5 times for example you will have five entries even if they are all the same. On Sun, Mar 22, 2009 at 2:11 PM, Daniel Dale wrote: > Thanks for all the help. I appreciate it. just had a thought though. > continuing the way I'm doing it now all the games I enter will be lost > when I close the program right ? > > is there a way i can code it so the user is asked for the > title,rating,condition and etc of a game. when they put it in is > stored in a file with the rest of the games they input. > then they can sort them or list them by rating,platform,or genre. > -- > Posted via http://www.ruby-forum.com/. > > -- There was a man, they called him mad. The more he gave, the more he had. --000325579e82a6355a0465bb35cc--