From: Samantha Date: 2007-03-02T01:15:11+09:00 Subject: Re: Stepping out on a Limb - some very ugly code ------=_Part_66445_14109337.1172765703460 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Comments inline so I can make sure I really "understand" what's being done here... On 3/1/07, Brian Burns wrote: > > Well, there's always more than one way to do anything, > but here's one late night hack :) > > #!/usr/bin/env ruby > > class ResumeBuilder > def initialize > @data = {} > @fields = ['First Name', > 'Last Name' , > 'Address' , > 'City' , > 'State' , > 'Zip' ] > end --- I'm assuming that here you are defining the class that is ResumeBuilder... you've got the @data and @fields that are instance variables, right? @data is an empty hash and @fields is an array... def prompt > @fields.each do |field| > val = @data[field] > print "Please enter your #{field}#{(' (' + val + ')') if val}:" > val = gets.chomp > @data[field] = val if val != '' > end > end --- Here you're defining the prompt method... and inserting each item from the @field array into the hash... then you're putting the answer that is given into the value for the item in the hash? (wow, that's a hard one to articulate when ya don't know all the lingo" and then you are ending it if val doesn't have anything? def confirm? > puts "You entered:" > @fields.each do |field| > puts field + ': ' + @data[field].to_s > end > print "Is this correct? (Y/n)" > gets.chomp == 'Y' > end > end --- here is the confirmation section... You're telling the user what they entered for each value by iterating through the hash/array? resume = ResumeBuilder.new > resume.prompt > resume.prompt until resume.confirm? and here you are defining that the variable resume is a new instance of the Class ResumeBuilder... I'm kind of lost on the last line... I didn't bother with the formatting, but you get the idea. > You might also look at using a Struct. Will do! Thanks for the input! I'm finding that this is a really good way to learn. -Brian > > -- > Posted via http://www.ruby-forum.com/. > > -- Samantha http://www.babygeek.org/ "Beware when the great God lets loose a thinker on this planet. Then all things are at risk." --Ralph Waldo Emerson ------=_Part_66445_14109337.1172765703460--