From: dblack@... Date: 2007-03-01T12:23:52+09:00 Subject: Re: Stepping out on a Limb - some very ugly code Hi -- On Thu, 1 Mar 2007, Samantha wrote: > After taking several suggestions, I've come up with 91 lines of code > (including blank lines because I like organizing things). > > I have a few issues in certain areas of the code... > > I'll post all 91 lines (including lines intentionally left blank), and > explain what I'm having go wrong... I'm just not getting it, but maybe I > don't quite understand certain things... (probably, not maybe ;) (And > please excuse the rude prompts - I'm not really this rude, nor would I write > such a rude program for deployment into the world.) > > #ResumeBuilder.rb > > #This is the section that defines a prompt. > def prompt(string) > puts(string) > gets.chomp > end > > #This section defines a prompt that requires a yes or no answer. > def boolean_prompt(string) > prompt("#{string} (yes/no)").downcase == "yes" > end > > #Main program logic for User Identity > puts("Welcome to Resume Builder v.1") > > first_name = prompt("Please enter your first name: ").capitalize! > last_name = prompt("Please enter your last name: ").capitalize! > > #This verifies that the user is who they said they were. > correct = boolean_prompt("So, your name is #{first_name} #{last_name}?") > if correct > puts("Great! Let's get started, #{first_name}!") > else > puts("Please come back when you know who you are.") > exit 1 > end > > ------------When I get to this point, if I typed in the answers to the > prompts with the first letter capitalized (ie Samantha for the first name), > when the program verifies what I typed whatever values it is verifying, as > blank... That's because capitalize!, like a lot of bang methods, returns nil if no change has occurred in the receiver. So David.capitalize! is nil. > puts("Your skills are as follows:\n") > tech_skills.each do |skill| > puts skill > end It's much easier than that: puts tech_skills :-) > #This section gathers experience from the user. > company1 = Hash.new > ["Company Name","Company City","Company State","Start Date","End > Date","Position Held","Job Duties"].each do |input| > puts("Please enter your #{input}: ") > company1 = gets.chomp That's wrong; it should be: company1[input] = gets.chomp since you want to set the relevant hash key. Also, make sure that there's no newline between "End" and "Date", as that will cause company1["End Date"] to be nil (as opposed to company1["End \nDate"]). > correct = boolean_prompt("You worked at " + company1["Company Name"] + " as > a " + company1["Position Held"] + " from " + company1["Start Date"] + " > until " + company1["End Date"] + " and your job description was as follows: > \n" + company1["Job Duties"] + "\n" + company1["Company Name"] + " was > located in " + company1["Company City"] + ", " + company1["Company State"] + > "Is this correct? ") Consider a here-document: prompt = <