I like Dave's answer the best. It's a nice technique.
Now I have this thing about reducing lines of code for no reason, so
here is a savings of a line or 2:
File.open('phonespec.txt', 'a') do |myfile|
puts "Welcome to MyAddressbook. Please follow the prompts."
puts "If you wish to end data entry, you may do so at any time"
puts "by type the word END into a prompt."
catch (:done) do
loop do
result = []
["First name", "Last name", "Phone"].each do |prompt|
print "\t#{prompt}: "
result << gets.chop
throw :done if result[-1] == "END"
end
myfile.puts result.join("\t")
end
end
end
Of course Dave's is better from a maintenance standpoint (and his also
deals with input EOF), I'm just having fun.
-joe