2014-10-03 68 views
-3
file_1 = File.open('Data_family.txt', 'r') 
user1 = go 
while user1 != "stop" 
    print "whould you like to create: " 
    user1 = gets.chomp 
    print "what is your relation: " 
    relation = gets.chomp 
    file_1.syswrite "this is your " + relation 
    file_1.syswrite "\n" 
end 
file_1.close 

我很困惑,爲什麼塊沒有運行。我喜歡對子級創建家譜數據庫但它不會讓我將數據添加到我打開不能添加數據到文件

+2

什麼是你的問題? – sawa 2014-10-03 17:14:04

+0

如果您還將錯誤信息提供給您,它將有所幫助。我的猜測是,在第二行,'user1 = go'應該在引號內:'user1 =「go」'。 – htanata 2014-10-03 17:17:43

+0

爲什麼它不允許我進入循環 – 2014-10-03 17:22:30

回答

1

文件我認爲你試圖做一些事情,如:

#!/usr/bin/eval ruby 

File.open('Data_family.txt', 'w') do |file_1| 
    loop do 
    print "Who would you like to create: " 
    user1 = gets.chomp 
    break if user1 == "stop" 
    print "what is your relation: " 
    relation = gets.chomp 
    file_1.puts "this is your " + relation 
    end 
end #File autocloses at the end of the block