【发布时间】:2010-08-04 15:19:46
【问题描述】:
在我的程序中,我收到一个错误,上面写着 ./ruby_camping.rb:91:in `-': nil can't be coerced into Fixnum (TypeError)。我想做的是结帐我刚刚签到的客人。这是结帐部分的代码块:
def self.check_out
puts "Welcome to checkout!"
puts $camping.current_guests
puts " Here are the current guests, who do you want to checkout?!"
puts "State plot number "
plot = gets.chomp.to_i
guest = $camping.current_guests[plot-1]
puts "State the date for your checkout (a number bigger then " + guest.arrived.to_s + "): "
# it should not be possible for a guest to checkout before she has checked in
departureDate = gets.chomp.to_i
guestStayedDays = departureDate - guest.arrived #Days the guest has stayed
while (guestStayedDays < 1) do
puts "The date for checkout is not valid. The guest checked in " + guest.arrived.to_s
puts "Please state a new date."
departureDate = gets.chomp.to_i
guestStayedDays = departureDate - guest.arrived
end
guest.departure = departureDate
guest.plot.increase(guestStayedDays) # increases the electricity meter
puts guest # prints the guest
$camping.current_guests[plot-1] = nil # emptys the plot
end
end
departmentDate怎么还是nil呢?感谢您的帮助!
【问题讨论】:
标签: ruby