0
獲取錯誤私有方法'被要求(NoMethodError)紅寶石
"private method `gets' called for `ot,Room 203,Healthcare Info Session,2014,6,17,14,0\n":String (NoMethodError)"
和不知道在哪裏我的代碼是錯誤的。
而且在appointments.txt
第一行:
ot,Room 203,Healthcare Info Session,2014,6,17,14,0
可有人請讓我知道需要我的代碼改變什麼:
appointments = [ ]
file_object = File.open("appointments.txt", "r")
while line = file_object.gets
fields = line.gets.chomp.split(',')
appointment_type = [0]
if appointment_type == 'ot'
location = fields[1]
purpose = fields[2]
year = fields[3].to_i
month = fields[4].to_i
day = fields[5].to_i
hour = fields[6].to_i
minute = fields[7].to_i
appt1 = OneTimeAppointment.new("Dentist", "Cleaning", 4, 45, 5, 20, 2017)
appointments.push(appt1)
else
location = fields[1]
purpose = fields[2]
hour = fields[3].to_i
minute = fields[4].to_i
day = fields[5].to_i
appt2 = MonthlyAppointment.new("Doctor", "Cold", 2, 30, 15)
appointments.push(appt2)
end
end
'新':無效日期(引發ArgumentError)顯示出來時,我的代碼添加到我的文件 – Julian
如何解決這個問題? – Julian
收到錯誤 「RB:37:在'新':無效日期(引發ArgumentError)」 – Julian